package co.yixiang.modules.shop.rest;

import co.yixiang.enums.BillDetailEnum;
import co.yixiang.enums.BillEnum;
import co.yixiang.modules.activity.domain.YxStoreCombination;
import co.yixiang.modules.activity.domain.YxStoreSeckill;
import co.yixiang.modules.activity.service.YxStoreCombinationService;
import co.yixiang.modules.activity.service.YxStorePinkService;
import co.yixiang.modules.activity.service.YxStoreSeckillService;
import co.yixiang.modules.order.domain.YxStoreOrder;
import co.yixiang.modules.order.service.YxStoreOrderCartInfoService;
import co.yixiang.modules.order.service.YxStoreOrderService;
import co.yixiang.modules.product.domain.YxStoreProduct;
import co.yixiang.modules.product.service.YxStoreProductService;
import co.yixiang.modules.template.domain.YxSystemCity;
import co.yixiang.modules.template.service.YxSystemCityService;
import co.yixiang.modules.user.domain.YxUser;
import co.yixiang.modules.user.service.AreaService;
import co.yixiang.modules.user.service.YxUserBillService;
import co.yixiang.modules.user.service.YxUserLevelService;
import co.yixiang.modules.user.service.YxUserService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.*;

@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(value = "分润方法", tags = "返佣:分润", description = "分润")
public class CommissionMainController {
    //private  YxUserServiceImpl yxUserService;
    @Autowired
    private final YxUserService yxUserService;
    private final YxUserLevelService yxUserLevelService;
    private final YxStoreOrderService storeOrderService;
    private final YxStoreOrderCartInfoService storeOrderCartInfoService;
    private final YxUserBillService yxUserBillService;
    private final AreaService areaService;
    private final YxStoreCombinationService storeCombinationService;
    private final YxStorePinkService storePinkService;
    private final YxSystemCityService systemCityService;
    private final YxStoreProductService productService;
    private final YxStoreSeckillService yxStoreSeckillService;

    // 新建用户更新上级用户数据
    public void updateParentUserCount(String user_id) {
        log.info("user_id====="+user_id);

        //YxUser user = yxUserService.getById(Long.valueOf(user_id));
        String userId =user_id.split(",")[0];
        String spreadId =user_id.split(",")[1];
        log.info("user====="+userId);
        log.info("spreadId====="+spreadId);
        yxUserService.initPath(Long.valueOf(userId),spreadId);
        log.info("user11111111====="+userId);
        /*JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
        log.info("parentUsers====="+parentUsers);
        Map<Integer,String> checkMap = new HashMap();
        int i = 1;
        Set<String> keySet= parentUsers.keySet();
        for (String key : keySet) {
            //String key = it.next().toString();
            JSONObject item = parentUsers.getJSONObject(key);
            //int member_level = item.getInteger("level");
            int under_count =  item.getInteger("spread_count");
            int normal_count =  item.getInteger("normal_count");
            int vip_count =  item.getInteger("vip_count");
            if(i==1) {
                under_count++;
            }
            i++;
            YxUser yxUser = yxUserService.getById(Long.valueOf(item.getString("id")));
            yxUser.setSpreadCount(under_count);
            yxUser.setNormalCount(normal_count+1);
            yxUser.setVipCount(vip_count);
            yxUserService.updateById(yxUser);
        }*/

    }

    // 判断购买产品类型，确定分佣方式
    public  void checkOrderGoodsclass(String orderid) {
        System.out.println("orderid==========="+orderid);
        JSONObject jsonObj = storeOrderCartInfoService.getGoodsclassByOrderid(Long.valueOf(orderid));
        //String gc_id = jsonObj.getString("gc_id");
        String goods_id = jsonObj.getString("goods_id");
        String user_id = jsonObj.getString("user_id");
        String member_level = jsonObj.getString("member_level");
        double price = jsonObj.getDouble("price");
        double totalPrice = jsonObj.getDouble("totalPrice");
        int  amount = jsonObj.getInteger("count");
        String payment_id = jsonObj.getString("payment_id");
        String combinationId = jsonObj.getString("combinationId");
        String seckillId = jsonObj.getString("seckillId");
        String isFree =jsonObj.getString("isFree");
        int checkOrderCount = yxUserBillService.checkCommission4order(Long.valueOf(orderid));
        System.out.println("orderid11111111111==========="+orderid);
        /*if (gc_id.equals("4")) {*/
        if(Long.valueOf(combinationId).intValue()>0){//推三返一
            if("yue".equals(payment_id) || "balanceSum".equals(payment_id)){
                yueRebateOrderCommission(user_id, goods_id, combinationId,orderid);
            }else{
                rebateOrderCommission(user_id, goods_id, combinationId,orderid);
            }
        }else if(Long.valueOf(seckillId).intValue()>0){//秒杀
            if("yue".equals(payment_id) || "balanceSum".equals(payment_id)){
                yueSeckillOrderCommission(user_id, goods_id, seckillId,orderid,amount);
            }else{
                seckillOrderCommission(user_id, goods_id, seckillId,orderid,amount);
            }
        }else{
            if(checkOrderCount ==0){
                if("yue".equals(payment_id) || "balanceSum".equals(payment_id)){
                    //yePayOrderCommission(user_id, goods_id, member_level,orderid,amount);
                    //余额支付
                    if(price == 49.9) {
                        yePayvipOrderCommission(user_id, goods_id, member_level,orderid,amount,price,payment_id);
                    }else if(price == 299){
                        //yePayshlsOrderCommission(user_id, goods_id, member_level,orderid,amount,price,payment_id);//299瘦身零售
                        yePayshlsOrder4mmCommission(user_id, goods_id, member_level,orderid,amount,price,payment_id);//299瘦身零售
                    }else if(price == 399){
                        //yePayshhdOrderCommission(user_id, goods_id, member_level,orderid,amount,price,payment_id);//399瘦身活动
                        yePayshlsOrder4mmNewCommission(user_id, goods_id, member_level,orderid,amount,price,payment_id);//399瘦身零售
                    }else if(price == 618){
                        //yePayshhdOrderCommission(user_id, goods_id, member_level,orderid,amount,price,payment_id);//399瘦身活动
                        yePayshlsOrder4lbNewCommission(user_id, goods_id, member_level,orderid,amount,price,payment_id);//399瘦身零售
                    }else if(price == 1618){
                        //yePayshhdOrderCommission(user_id, goods_id, member_level,orderid,amount,price,payment_id);//399瘦身活动
                        yePayshlsOrder4dlbNewCommission(user_id, goods_id, member_level,orderid,amount,price,payment_id);//399瘦身零售
                    }else if(price == 59.9 ||price == 79.9){
                        yePayvipOrderCommission(user_id, goods_id, member_level,orderid,amount,price,payment_id);//59.9
                    }else if(price == 1390 ){
                        yePayvipOrderCommission4Package(user_id, goods_id, member_level,orderid,amount,price,payment_id);//1390套餐
                    }else if(price == 2990){
                        //yePayshlsOrderCommission(user_id, goods_id, member_level,orderid,amount,price,payment_id);//299瘦身零售
                        yePayshlsOrder4NewLiBaoCommission(user_id, goods_id, member_level,orderid,amount,price,payment_id);//299瘦身零售
                    }else{
                    if("true".equals(isFree)){
                        yePayPostageOrderCommission(user_id, goods_id, member_level,orderid,amount,totalPrice,payment_id);
                    }
                }
                }else{
                    if(price == 49.9) {
                        vipOrderCommission(user_id, goods_id, member_level,orderid,amount);
                    }else if(price == 299){
                        //shlsOrderCommission(user_id, goods_id, member_level,orderid,amount);//299瘦身零售
                        shlsOrder4mmCommission(user_id, goods_id, member_level,orderid,amount);//299瘦身零售
                    }else if(price == 399){
                        //shhdOrderCommission(user_id, goods_id, member_level,orderid,amount);//399瘦身活动
                        shlsOrder4mmNewCommission(user_id, goods_id, member_level,orderid,amount);//399瘦身零售
                    }else if(price == 618){
                        //shhdOrderCommission(user_id, goods_id, member_level,orderid,amount);//399瘦身活动
                        shlsOrder4lbNewCommission(user_id, goods_id, member_level,orderid,amount);//399瘦身零售
                    }else if(price == 1618){
                        //shhdOrderCommission(user_id, goods_id, member_level,orderid,amount);//399瘦身活动
                        shlsOrder4dlbNewCommission(user_id, goods_id, member_level,orderid,amount);//399瘦身零售
                    }else if(price == 59.9 ||price == 79.9 ){
                        vipOrderCommission(user_id, goods_id, member_level,orderid,amount);//59.9
                    }else if(price == 1390 ){
                        vipOrderCommission4Package(user_id, goods_id, member_level,orderid,amount);//1390套餐
                    }else if(price == 2990){
                        shlsOrder4NewLiBaoCommission(user_id, goods_id, member_level,orderid,amount);//299瘦身零售
                    }/*else if(price == 0) {
						if("98536".equals(goods_id) ||"98525".equals(goods_id)){
							postageOrderCommission(user_id, goods_id, member_level,orderid,amount);
						}
					}*/
                }
            }
        }
			/*}else {
			freeOrderCommission(user_id,orderid,goods_id);
		}*/
        System.out.println("orderid2222222222222==========="+orderid);
    }

	/*// 29.9元产品分润
		private  void tnOrderCommission(String user_id,String orderid,String goods_id)
				throws GeneralException {
			JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
			if (!Validate.isEmpty(commissionSetting)) {
				JSONObject parentUsers = userMgr.getParentUsers(user_id);
				Map<Integer,String> checkMap = new HashMap();
				int i = 1;
				for (Iterator it = parentUsers.keys(); it.hasNext();) {
					String key = it.next().toString();
					JSONObject item = parentUsers.getJSONObject(key);
					int member_level = item.getInt("member_level");
					if (i == 1) {
						if (member_level > 1) {
							Commission c1= new Commission();
							c1.setCommission_sum(new BigDecimal("3"));
							c1.setCommission_type("1");
							c1.setOrder_id(Long.parseLong(orderid));
							c1.setUser_id(Long.parseLong(item.get("id").toString()));
							commissionMgr.addNew(c1);
							System.out.println("购买29.9产品，直属分3元");
						}
					} else if (i == 2) {
						if (member_level == 4) {
							Commission c1= new Commission();
							c1.setCommission_sum(new BigDecimal("1"));
							c1.setCommission_type("2");
							c1.setOrder_id(Long.parseLong(orderid));
							c1.setUser_id(Long.parseLong(item.get("id").toString()));
							commissionMgr.addNew(c1);
							System.out.println("购买29.9产品，钻石间推分1元");
						}
					}
					if (member_level > 4) {
						if(!checkMap.containsKey(member_level)) {
							Commission c1= new Commission();
							c1.setCommission_sum(new BigDecimal("1"));
							c1.setCommission_type("3");
							c1.setOrder_id(Long.parseLong(orderid));
							c1.setUser_id(Long.parseLong(item.get("id").toString()));
							commissionMgr.addNew(c1);
							System.out.println("购买29.9产品，皇冠团队分1元");
							checkMap.put(member_level, "has");
						}
					}

					i++;
				}
			}
		}
		*/
    // 购买免费或积分产品分润
	/*private  void freeOrderCommission(String user_id,String orderid,String goods_id)
			throws GeneralException {
		JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
		if (!Validate.isEmpty(commissionSetting)) {
			JSONObject commission = JSONObject.fromObject(commissionSetting
					.getString("0"));
			String goods_com = commission.getString("goods_com");
			String under_goods_com = commission.getString("under_goods_com");
			String team_com = commission.getString("team_com");
			JSONObject parentUsers = userMgr.getParentUsers(user_id);
			Map<Integer,String> checkMap = new HashMap();
			int i = 1;
			for (Iterator it = parentUsers.keys(); it.hasNext();) {
				String key = it.next().toString();
				JSONObject item = parentUsers.getJSONObject(key);
				int member_level = item.getInt("member_level");
				if(member_level == 6) {
					member_level = 5;
				}
				if (i == 1) {
					if (member_level > 1) {
						Commission c1= new Commission();
						c1.setCommission_sum(new BigDecimal(goods_com));
						c1.setCommission_type("4");
						c1.setOrder_id(Long.parseLong(orderid));
						c1.setUser_id(Long.parseLong(item.get("id").toString()));
						commissionMgr.addNew(c1);
						System.out.println("购买免费产品，直属分"+goods_com+"元");
					}
				} else if (i == 2) {
					if (member_level == 4) {
						Commission c1= new Commission();
						c1.setCommission_sum(new BigDecimal(under_goods_com));
						c1.setCommission_type("5");
						c1.setOrder_id(Long.parseLong(orderid));
						c1.setUser_id(Long.parseLong(item.get("id").toString()));
						commissionMgr.addNew(c1);
						System.out.println("购买免费产品，钻石间推分"+under_goods_com+"元");
					}
				}
				if (member_level > 4) {
					if(!checkMap.containsKey(member_level)) {
						Commission c1= new Commission();
						c1.setCommission_sum(new BigDecimal(team_com));
						c1.setCommission_type("6");
						c1.setOrder_id(Long.parseLong(orderid));
						c1.setUser_id(Long.parseLong(item.get("id").toString()));
						commissionMgr.addNew(c1);
						System.out.println("购买免费产品，皇冠团队分"+team_com+"元");
						checkMap.put(member_level, "has");
					}
				}

				i++;
			}
		}
	}*/

    // 购买VIP产品分润
    private  void vipOrderCommission(String user_id, String goods_id,
                                           String member_level,String orderid, int amount) {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("1", "10");
        commissionSetting.put("2", "5");
        commissionSetting.put("3", "5");
        commissionSetting.put("4", "5");
        commissionSetting.put("5", "4");
        //if (!Validate.isEmpty(commissionSetting)) {
        Map<String, String> team_com_commissionmap = new HashMap();
        for(int i=0;i<amount;i++) {
            JSONObject main = new JSONObject();
            main.put("id", user_id);
            main.put("member_level", member_level);
            JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
            int index = 1;
            int level = 1;
            parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
            Map<String, String> team_com_map = new HashMap();
            userCommissionUpdate(main, index, commissionSetting,
                    team_com_map, orderid, amount,team_com_commissionmap);
            Set<String> keySet = parentUsers.keySet();
            for (String key : keySet) {
                //String key = it.next().toString();
                JSONObject item = parentUsers.getJSONObject(key);
                String memberLevel =item.get("member_level").toString();
                log.info("memberLevel====="+memberLevel);
                int mLevel =0;
                if(!isEmpty(memberLevel)){
                    mLevel =Integer.parseInt(memberLevel);
                }
                log.info("mLevel====="+mLevel);
                log.info("level====="+level);
                if(mLevel>=level) {
                    userCommissionUpdate(item, index, commissionSetting,
                            team_com_map, orderid, amount, team_com_commissionmap);
                    level =mLevel;
                }
                index++;
            }
        }

        if(!isEmpty(team_com_commissionmap)){
            team_com_commissionmap.forEach((key, value) -> {
                YxUser user =yxUserService.getById(Long.valueOf(key));
                yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                        BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
            });
        }
            /*userMemberLevelUpdate(main);
            for (String key : keySet) {
                //String key = it.next().toString();
                JSONObject item = parentUsers.getJSONObject(key);
                userMemberLevelUpdate(item);
            }*/


        //}
    }

    // 购买邮费专区产品分润
    /*private void postageOrderCommission(String user_id, String goods_id,
                                               String member_level,String orderid, int amount) throws GeneralException {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("2", "0.5");
        commissionSetting.put("3", "0.5");
        commissionSetting.put("4", "0.5");
        commissionSetting.put("5", "0.5");
        commissionSetting.put("6", "0.5");
        //if (!Validate.isEmpty(commissionSetting)) {
            JSONObject main = new JSONObject();
            main.put("id", user_id);
            main.put("member_level", member_level);
            int index = 1;
            JSONObject parentUsers = yxUserService.getParentUsers4UnPeer(user_id, member_level);
            System.out.println("parentUsers==========="+parentUsers);
            //parentUsers = userMgr.getParentUsers(user_id);
            Map<String, String> team_com_map = new HashMap();
            Map<String, String> team_map = new HashMap();
				*//*userCommissionUpdate(main, index, commissionSetting,
						team_com_map,orderid,amount);*//*
            Set<String> keySet= parentUsers.keySet();
            for (String key : keySet) {
                //String key = it.next().toString();
                JSONObject item = parentUsers.getJSONObject(key);
                String main_member_level = item.get("member_level").toString();
                if(!team_map.containsKey(main_member_level)){
                    userPostageCommissionUpdate(item, index, commissionSetting,
                            team_com_map,orderid,amount);
                    team_map.put(main_member_level, "Y");
                    index++;
                }
            }
				*//*userMemberLevelUpdate(main);
				for (Iterator it = parentUsers.keys(); it.hasNext();) {
					String key = it.next().toString();
					JSONObject item = parentUsers.getJSONObject(key);
					userMemberLevelUpdate(item);
				}
*//*

        //}
    }*/



    // 购买399瘦身活动产品分润(弃用)
    private  void shhdOrderCommission(String user_id, String goods_id,
                                            String member_level,String orderid, int amount) {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("1", "100");
        commissionSetting.put("2", "30");
        commissionSetting.put("3", "20");
        commissionSetting.put("4", "20");
        commissionSetting.put("5", "10");
        //if (!Validate.isEmpty(commissionSetting)) {
            JSONObject main = new JSONObject();
            main.put("id", user_id);
            main.put("member_level", member_level);
            JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
            int index = 1;
            parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
            Map<String, String> team_com_map = new HashMap();
            userSlimmingCommissionUpdate(main, index, commissionSetting,
                    team_com_map,orderid,amount);
            YxUser user = yxUserService.getById(Long.valueOf(user_id));
            user.setWhether_slim("1");
            user.setValidity_date(new Date());
            //userMgr.updateUser4slimVip(user_id);
            yxUserService.updateById(user);//更新购买399用户状态变化
            Set<String> keySet= parentUsers.keySet();
            for (String key : keySet) {
                //String key = it.next().toString();
                JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                userSlimmingCommissionUpdate(item, index, commissionSetting,
                        team_com_map,orderid,amount);
                index++;
            }
            //userMemberLevelUpdate(main);


            String whether_slim =user.getWhether_slim();
            if(isEmpty(whether_slim)){
                whether_slim ="0";
            }
            main.put("whether_slim", whether_slim);
            for (String key : keySet) {
                //String key = it.next().toString();
                JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                //userMemberLevelUpdate(item);
            }


       // }
    }

    // 购买299瘦身零售产品分润(弃用)
    private  void shlsOrderCommission(String user_id, String goods_id,
                                            String member_level,String orderid, int amount){
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("1", "100");
        commissionSetting.put("2", "30");
        commissionSetting.put("3", "20");
        commissionSetting.put("4", "20");
        commissionSetting.put("5", "10");
        if (!isEmpty(commissionSetting)) {
            JSONObject main = new JSONObject();
            main.put("id", user_id);
            main.put("member_level", member_level);
            JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
            YxUser user = yxUserService.getById(Long.valueOf(user_id));
            YxStoreProduct product =productService.getById(Long.valueOf(goods_id));
            int index = 1;
            parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
            Map<String, String> team_com_map = new HashMap();
            userSlimmingSaleCommissionUpdate(main, index, commissionSetting,
                    team_com_map,orderid,amount);
            //userMgr.updateUser4slimVip(user_id);//更新购买399用户状态变化
            if(!"Y".equals(user.getWhetherVipSlim())){
                if(product.getIsVip() ==1){
                    user = yxUserService.getById(Long.valueOf(user_id));
                    user.setWhetherVipSlim("Y");
                    user.setVipDate(new Date());
                    yxUserService.updateById(user);
                }
            }
            Set<String> keySet= parentUsers.keySet();
            for (String key : keySet) {
                //String key = it.next().toString();
                JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                userSlimmingSaleCommissionUpdate(item, index, commissionSetting,
                        team_com_map,orderid,amount);
                index++;
            }
            //userMemberLevelUpdate(main);
            for (String key : keySet) {
                //String key = it.next().toString();
                JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                //userMemberLevelUpdate(item);
            }


        }
    }

    // 购买299面膜产品分润
    private  void shlsOrder4mmCommission(String user_id, String goods_id,
                                               String member_level,String orderid, int amount) {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        //省市级分润
        BigDecimal operateBigDecimal =new BigDecimal("2").multiply(new BigDecimal(amount));
        operateCommissionUpdate(orderid,operateBigDecimal);
        int pjSum =5;
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("1", "60");
        commissionSetting.put("2", "40");
        commissionSetting.put("3", "35");
        commissionSetting.put("4", "25");
        commissionSetting.put("5", "25");
        if (!isEmpty(commissionSetting)) {
            Map<String, String> team_com_commissionmap = new HashMap();
            Map<String, String> team_com_pjmap = new HashMap();//平级集合
            for(int i=0;i<amount;i++) {
                JSONObject main = new JSONObject();
                int orderCount =i+1;
                YxUser user = yxUserService.getById(Long.valueOf(user_id));
                YxStoreProduct product =productService.getById(Long.valueOf(goods_id));
                main.put("id", user_id);
                main.put("member_level", user.getLevel());
                JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                int index = 1;
                int level = 1;
                parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                Map<String, String> team_com_map = new HashMap();
                userSlimmingSale4mmCommissionUpdate(main, index, commissionSetting,
                        team_com_map, orderid, amount,team_com_commissionmap,team_com_pjmap,pjSum);
                //userMgr.updateUser4slimVip(user_id);//更新购买399用户状态变化
                if(!"Y".equals(user.getWhetherVipSlim())){
                    if(orderCount ==amount){
                        if(product.getIsVip() ==1){
                            user = yxUserService.getById(Long.valueOf(user_id));
                            user.setWhetherVipSlim("Y");
                            user.setVipDate(new Date());
                            yxUserService.updateById(user);
                        }
                    }
                }
                Set<String> keySet = parentUsers.keySet();
                log.info("parentUsers====="+parentUsers);
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    String memberLevel =item.get("member_level").toString();
                    log.info("memberLevel====="+memberLevel);
                    int mLevel =0;
                    if(!isEmpty(memberLevel)){
                        mLevel =Integer.parseInt(memberLevel);
                    }
                    log.info("mLevel====="+mLevel);
                    log.info("level====="+level);
                    if(mLevel>=level){
                        userSlimmingSale4mmCommissionUpdate(item, index, commissionSetting,
                                team_com_map, orderid, amount,team_com_commissionmap,team_com_pjmap,pjSum);
                        level =mLevel;
                    }

                    index++;
                }
                userMemberLevelUpdate(main, orderid, orderCount);
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    userMemberLevelUpdate(item, orderid, orderCount);
                }
            }

            if(!isEmpty(team_com_commissionmap)){
                team_com_commissionmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }

            if(!isEmpty(team_com_pjmap)){
                team_com_pjmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }

        }

    }

    // 购买399面膜产品分润
    private  void shlsOrder4mmNewCommission(String user_id, String goods_id,
                                         String member_level,String orderid, int amount) {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        //省市级分润
        BigDecimal operateBigDecimal =new BigDecimal("2").multiply(new BigDecimal(amount));
        operateCommissionUpdate(orderid,operateBigDecimal);
        int pjSum =5;
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("1", "60");
        commissionSetting.put("2", "70");
        commissionSetting.put("3", "50");
        commissionSetting.put("4", "35");
        commissionSetting.put("5", "30");
        if (!isEmpty(commissionSetting)) {
            Map<String, String> team_com_commissionmap = new HashMap();
            Map<String, String> team_com_pjmap = new HashMap();//平级集合
            for(int i=0;i<amount;i++){
                JSONObject main = new JSONObject();
                int orderCount =i+1;
                YxUser user = yxUserService.getById(Long.valueOf(user_id));
                YxStoreProduct product =productService.getById(Long.valueOf(goods_id));
                main.put("id", user_id);
                main.put("member_level", user.getLevel());
                JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                int index = 1;
                int level = 1;
                parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                Map<String, String> team_com_map = new HashMap();
                userSlimmingSale4mmCommissionUpdate(main, index, commissionSetting,
                        team_com_map,orderid,amount,team_com_commissionmap,team_com_pjmap,pjSum);
                //userMgr.updateUser4slimVip(user_id);//更新购买399用户状态变化
                if(!"Y".equals(user.getWhetherVipSlim())){
                    if(orderCount ==amount){
                        if(product.getIsVip() ==1){
                            user = yxUserService.getById(Long.valueOf(user_id));
                            user.setWhetherVipSlim("Y");
                            user.setVipDate(new Date());
                            yxUserService.updateById(user);
                        }
                    }
                }
                Set<String> keySet= parentUsers.keySet();
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    String memberLevel =item.get("member_level").toString();
                    log.info("memberLevel====="+memberLevel);
                    int mLevel =0;
                    if(!isEmpty(memberLevel)){
                        mLevel =Integer.parseInt(memberLevel);
                    }
                    log.info("mLevel====="+mLevel);
                    log.info("level====="+level);
                    if(mLevel>=level) {
                        userSlimmingSale4mmCommissionUpdate(item, index, commissionSetting,
                                team_com_map, orderid, amount, team_com_commissionmap, team_com_pjmap, pjSum);
                        level =mLevel;
                    }
                    index++;
                }
                userMemberLevelUpdate(main, orderid, orderCount);
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    userMemberLevelUpdate(item, orderid, orderCount);
                }
            }

            if(!isEmpty(team_com_commissionmap)){
                team_com_commissionmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }

            if(!isEmpty(team_com_pjmap)){
                team_com_pjmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }

        }

    }

    // 购买618大礼包产品分润
    private  void shlsOrder4lbNewCommission(String user_id, String goods_id,
                                            String member_level,String orderid, int amount) {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        //省市级分润
        BigDecimal operateBigDecimal =new BigDecimal("2").multiply(new BigDecimal(amount));
        operateCommissionUpdate(orderid,operateBigDecimal);
        int pjSum =5;
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("1", "100");
        commissionSetting.put("2", "65");
        commissionSetting.put("3", "70");
        commissionSetting.put("4", "50");
        commissionSetting.put("5", "50");
        if (!isEmpty(commissionSetting)) {
            Map<String, String> team_com_commissionmap = new HashMap();
            Map<String, String> team_com_pjmap = new HashMap();//平级集合
            YxStoreProduct product =productService.getById(Long.valueOf(goods_id));
            for(int i=0;i<amount;i++){
                JSONObject main = new JSONObject();
                int orderCount =0;
                if(i ==0){
                    orderCount =product.getSingular();
                }else{
                    orderCount =i*product.getSingular();
                }
                int count =i+1;//用于判断条件是否最后一个数量
                YxUser user = yxUserService.getById(Long.valueOf(user_id));
                main.put("id", user_id);
                main.put("member_level", user.getLevel());
                JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                int index = 1;
                int level = 1;
                parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                Map<String, String> team_com_map = new HashMap();
                userSlimmingSale4mmCommissionUpdate(main, index, commissionSetting,
                        team_com_map,orderid,amount,team_com_commissionmap,team_com_pjmap,pjSum);
                //userMgr.updateUser4slimVip(user_id);//更新购买399用户状态变化
                if(!"Y".equals(user.getWhetherVipSlim())){
                    if(count ==amount){
                        if(product.getIsVip() ==1){
                            user = yxUserService.getById(Long.valueOf(user_id));
                            user.setWhetherVipSlim("Y");
                            user.setVipDate(new Date());
                            yxUserService.updateById(user);
                        }
                    }
                }
                Set<String> keySet= parentUsers.keySet();
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    String memberLevel =item.get("member_level").toString();
                    log.info("memberLevel====="+memberLevel);
                    int mLevel =0;
                    if(!isEmpty(memberLevel)){
                        mLevel =Integer.parseInt(memberLevel);
                    }
                    log.info("mLevel====="+mLevel);
                    log.info("level====="+level);
                    if(mLevel>=level) {
                        userSlimmingSale4mmCommissionUpdate(item, index, commissionSetting,
                                team_com_map, orderid, amount, team_com_commissionmap, team_com_pjmap, pjSum);
                        level =mLevel;
                    }
                    index++;
                }
                userMemberLevelUpdate(main, orderid, orderCount);
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    userMemberLevelUpdate(item, orderid, orderCount);
                }
            }

            if(!isEmpty(team_com_commissionmap)){
                team_com_commissionmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }

            if(!isEmpty(team_com_pjmap)){
                team_com_pjmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }

        }

    }

    // 购买1618大礼包产品分润
    private  void shlsOrder4dlbNewCommission(String user_id, String goods_id,
                                            String member_level,String orderid, int amount) {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        //省市级分润
        BigDecimal operateBigDecimal =new BigDecimal("2").multiply(new BigDecimal(amount));
        operateCommissionUpdate(orderid,operateBigDecimal);
        int pjSum =20;
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("1", "280");
        commissionSetting.put("2", "170");
        commissionSetting.put("3", "170");
        commissionSetting.put("4", "160");
        commissionSetting.put("5", "120");
        if (!isEmpty(commissionSetting)) {
            Map<String, String> team_com_commissionmap = new HashMap();
            Map<String, String> team_com_pjmap = new HashMap();//平级集合
            YxStoreProduct product =productService.getById(Long.valueOf(goods_id));
            for(int i=0;i<amount;i++){
                JSONObject main = new JSONObject();
                int orderCount =0;
                if(i ==0){
                    orderCount =product.getSingular();
                }else{
                    orderCount =i*product.getSingular();
                }
                int count =i+1;//用于判断条件是否最后一个数量
                YxUser user = yxUserService.getById(Long.valueOf(user_id));
                main.put("id", user_id);
                main.put("member_level", user.getLevel());
                JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                int index = 1;
                int level = 1;
                parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                Map<String, String> team_com_map = new HashMap();
                userSlimmingSale4mmCommissionUpdate(main, index, commissionSetting,
                        team_com_map,orderid,amount,team_com_commissionmap,team_com_pjmap,pjSum);
                //userMgr.updateUser4slimVip(user_id);//更新购买399用户状态变化
                if(!"Y".equals(user.getWhetherVipSlim())){
                    if(count ==amount){
                        if(product.getIsVip() ==1){
                            user = yxUserService.getById(Long.valueOf(user_id));
                            user.setWhetherVipSlim("Y");
                            user.setVipDate(new Date());
                            yxUserService.updateById(user);
                        }
                    }
                }
                Set<String> keySet= parentUsers.keySet();
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    String memberLevel =item.get("member_level").toString();
                    log.info("memberLevel====="+memberLevel);
                    int mLevel =0;
                    if(!isEmpty(memberLevel)){
                        mLevel =Integer.parseInt(memberLevel);
                    }
                    log.info("mLevel====="+mLevel);
                    log.info("level====="+level);
                    if(mLevel>=level) {
                        userSlimmingSale4mmCommissionUpdate(item, index, commissionSetting,
                                team_com_map, orderid, amount, team_com_commissionmap, team_com_pjmap, pjSum);
                        level =mLevel;
                    }
                    index++;
                }
                userMemberLevelUpdate(main, orderid, orderCount);
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    userMemberLevelUpdate(item, orderid, orderCount);
                }
            }

            if(!isEmpty(team_com_commissionmap)){
                team_com_commissionmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }

            if(!isEmpty(team_com_pjmap)){
                team_com_pjmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }

        }

    }

    // 购买2990面膜产品分润
    private  void shlsOrder4NewLiBaoCommission(String user_id, String goods_id,
                                            String member_level,String orderid, int amount) {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        //省市级分润
        BigDecimal operateBigDecimal =new BigDecimal("20").multiply(new BigDecimal(amount));
        operateCommissionUpdate(orderid,operateBigDecimal);
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("1", "600");
        commissionSetting.put("2", "400");
        commissionSetting.put("3", "350");
        commissionSetting.put("4", "250");
        commissionSetting.put("5", "250");
        if (!isEmpty(commissionSetting)) {
            Map<String, String> team_com_commissionmap = new HashMap();
            Map<String, String> team_com_pjmap = new HashMap();//平级集合
            for(int i=0;i<amount;i++) {
                JSONObject main = new JSONObject();
                int orderCount =i+1;
                YxUser user = yxUserService.getById(Long.valueOf(user_id));
                main.put("id", user_id);
                main.put("member_level", user.getLevel());
                JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                int index = 1;
                int level = 1;
                parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                Map<String, String> team_com_map = new HashMap();
                userSlimmingSale4NewLiBaoCommissionUpdate(main, index, commissionSetting,
                        team_com_map, orderid, amount,team_com_commissionmap,team_com_pjmap);
                //userMgr.updateUser4slimVip(user_id);//更新购买399用户状态变化
                Set<String> keySet = parentUsers.keySet();
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    String memberLevel =item.get("member_level").toString();
                    log.info("memberLevel====="+memberLevel);
                    int mLevel =0;
                    if(!isEmpty(memberLevel)){
                        mLevel =Integer.parseInt(memberLevel);
                    }
                    log.info("mLevel====="+mLevel);
                    log.info("level====="+level);
                    if(mLevel>=level) {
                        userSlimmingSale4NewLiBaoCommissionUpdate(item, index, commissionSetting,
                                team_com_map, orderid, amount, team_com_commissionmap, team_com_pjmap);
                        level =mLevel;
                    }
                    index++;
                }
                userMemberLevelUpdate(main, orderid, orderCount);
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    userMemberLevelUpdate(item, orderid, orderCount);
                }
            }

            if(!isEmpty(team_com_commissionmap)){
                team_com_commissionmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }

            if(!isEmpty(team_com_pjmap)){
                team_com_pjmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }

        }

    }

    // 余额购买VIP产品分润
    private  void yePayvipOrderCommission(String user_id, String goods_id,
                                                String member_level,String orderid, int amount,double price,String payment_id) {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("1", "10");
        commissionSetting.put("2", "5");
        commissionSetting.put("3", "5");
        commissionSetting.put("4", "5");
        commissionSetting.put("5", "4");
        if (!isEmpty(commissionSetting)) {
            Map<String, String> team_com_commissionmap = new HashMap();
            for(int i=0;i<amount;i++) {
                int orderCount = i + 1;
                JSONObject main = new JSONObject();
                main.put("id", user_id);
                main.put("member_level", member_level);
                JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                int index = 1;
                int level = 1;
                parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                Map<String, String> team_com_map = new HashMap();
                yePayuserCommissionUpdate(main, index, commissionSetting,
                        team_com_map, orderid, amount, new BigDecimal(price), payment_id,team_com_commissionmap);
                Set<String> keySet = parentUsers.keySet();
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                    /*item.put("id", item.get("id").toString());
                    item.put("member_level", item.get("member_level").toString());*/
                    String memberLevel =item.get("member_level").toString();
                    log.info("memberLevel====="+memberLevel);
                    int mLevel =0;
                    if(!isEmpty(memberLevel)){
                        mLevel =Integer.parseInt(memberLevel);
                    }
                    log.info("mLevel====="+mLevel);
                    log.info("level====="+level);
                    if(mLevel>=level) {
                        userCommissionUpdate(item, index, commissionSetting,
                                team_com_map, orderid, amount, team_com_commissionmap);
                        level =mLevel;
                    }
                    index++;
                }
            }
            YxUser mainuser =yxUserService.getById(Long.valueOf(user_id));
            BigDecimal totalPrice =new BigDecimal(price).multiply(new BigDecimal(amount)).setScale(2, BigDecimal.ROUND_UP);
            BigDecimal maintotalSum =mainuser.getNowMoney().add(totalPrice);
            yxUserService.decPrice(mainuser.getUid(),totalPrice);
            yxUserBillService.expend4commission(mainuser.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_3.getValue(),totalPrice.doubleValue(),maintotalSum.doubleValue(), "积分抵扣",orderid);
            if(!isEmpty(team_com_commissionmap)){
                team_com_commissionmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }
            /*userMemberLevelUpdate(main);
            for (String key : keySet) {
                //String key = it.next().toString();
                JSONObject item = parentUsers.getJSONObject(key);
                *//*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*//*
                userMemberLevelUpdate(item);
            }*/


        }
    }

    // 购买399瘦身活动产品分润(弃用)
    private  void yePayshhdOrderCommission(String user_id, String goods_id,
                                                 String member_level,String orderid, int amount,double price,String payment_id) {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("1", "100");
        commissionSetting.put("2", "30");
        commissionSetting.put("3", "20");
        commissionSetting.put("4", "20");
        commissionSetting.put("5", "10");
        if (!isEmpty(commissionSetting)) {
            JSONObject main = new JSONObject();
            main.put("id", user_id);
            main.put("member_level", member_level);
            JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
            int index = 1;
            parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
            Map<String, String> team_com_map = new HashMap();
            yePayuserSlimmingCommissionUpdate(main, index, commissionSetting,
                    team_com_map,orderid,amount,new BigDecimal(price),payment_id);
            YxUser user = yxUserService.getById(Long.valueOf(user_id));
            user.setWhether_slim("1");
            user.setValidity_date(new Date());
            //userMgr.updateUser4slimVip(user_id);
            yxUserService.updateById(user);//更新购买399用户状态变化
            Set<String> keySet= parentUsers.keySet();
            for (String key : keySet) {
                //String key = it.next().toString();
                JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                userSlimmingCommissionUpdate(item, index, commissionSetting,
                        team_com_map,orderid,amount);
                index++;
            }
            //userMemberLevelUpdate(main);
            String whether_slim =user.getWhether_slim();
            if(isEmpty(whether_slim)){
                whether_slim ="0";
            }
            main.put("whether_slim", whether_slim);
            for (String key : keySet) {
                //String key = it.next().toString();
                JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                //userMemberLevelUpdate(item);
            }


        }
    }

    // 购买299瘦身零售产品分润(弃用)
    private  void yePayshlsOrderCommission(String user_id, String goods_id,
                                                 String member_level,String orderid, int amount,double price,String payment_id)  {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("1", "100");
        commissionSetting.put("2", "30");
        commissionSetting.put("3", "20");
        commissionSetting.put("4", "20");
        commissionSetting.put("5", "10");
        if (!isEmpty(commissionSetting)) {
            JSONObject main = new JSONObject();
            main.put("id", user_id);
            main.put("member_level", member_level);
            JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
            int index = 1;
            parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
            Map<String, String> team_com_map = new HashMap();
            yePayuserSlimmingSaleCommissionUpdate(main, index, commissionSetting,
                    team_com_map,orderid,amount,new BigDecimal(price),payment_id);
            //userMgr.updateUser4slimVip(user_id);//更新购买399用户状态变化
            Set<String> keySet= parentUsers.keySet();
            for (String key : keySet) {
                //String key = it.next().toString();
                JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                userSlimmingSaleCommissionUpdate(item, index, commissionSetting,
                        team_com_map,orderid,amount);
                index++;
            }
            //userMemberLevelUpdate(main);
            for (String key : keySet) {
                //String key = it.next().toString();
                JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                //userMemberLevelUpdate(item);
            }


        }
    }

    // 购买299面膜产品分润
    private  void yePayshlsOrder4mmCommission(String user_id, String goods_id,
                                                    String member_level,String orderid, int amount,double price,String payment_id) {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        //省市级分润
        BigDecimal operateBigDecimal =new BigDecimal("2").multiply(new BigDecimal(amount));
        operateCommissionUpdate(orderid,operateBigDecimal);
        int pjSum =5;
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("1", "60");
        commissionSetting.put("2", "40");
        commissionSetting.put("3", "35");
        commissionSetting.put("4", "25");
        commissionSetting.put("5", "25");
        if (!isEmpty(commissionSetting)) {
            Map<String, String> team_com_commissionmap = new HashMap();
            Map<String, String> team_com_pjmap = new HashMap();//平级集合
            for(int i=0;i<amount;i++) {
                int orderCount =i+1;
                JSONObject main = new JSONObject();
                YxUser user = yxUserService.getById(Long.valueOf(user_id));
                YxStoreProduct product =productService.getById(Long.valueOf(goods_id));
                main.put("id", user_id);
                main.put("member_level", user.getLevel());
                JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                int index = 1;
                int level = 1;
                parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                Map<String, String> team_com_map = new HashMap();
                yePayuserSlimmingSale4mmCommissionUpdate(main, index, commissionSetting,
                        team_com_map, orderid, amount, new BigDecimal(price), payment_id,team_com_commissionmap,team_com_pjmap,pjSum);
                System.out.println("team_com_map：" + team_com_map);
                //用户购买过vip产品后回填标识到用户表
                if(!"Y".equals(user.getWhetherVipSlim())){
                    if(orderCount ==amount){
                        if(product.getIsVip() ==1){
                            user = yxUserService.getById(Long.valueOf(user_id));
                            user.setWhetherVipSlim("Y");
                            user.setVipDate(new Date());
                            yxUserService.updateById(user);
                        }
                    }
                }
                //userMgr.updateUser4slimVip(user_id);//更新购买399用户状态变化
                Set<String> keySet = parentUsers.keySet();
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    String memberLevel =item.get("member_level").toString();
                    log.info("memberLevel====="+memberLevel);
                    int mLevel =0;
                    if(!isEmpty(memberLevel)){
                        mLevel =Integer.parseInt(memberLevel);
                    }
                    log.info("mLevel====="+mLevel);
                    log.info("level====="+level);
                    if(mLevel>=level) {
                        userSlimmingSale4mmCommissionUpdate(item, index, commissionSetting,
                                team_com_map, orderid, amount, team_com_commissionmap, team_com_pjmap, pjSum);
                        level =mLevel;
                    }
                    index++;
                }
                System.out.println("team_com_map1111111111：" + team_com_map);
                userMemberLevelUpdate(main, orderid, orderCount);
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    userMemberLevelUpdate(item, orderid, orderCount);
                }
            }
            YxUser mainuser =yxUserService.getById(Long.valueOf(user_id));
            BigDecimal totalPrice =new BigDecimal(price).multiply(new BigDecimal(amount)).setScale(2, BigDecimal.ROUND_UP);
            BigDecimal maintotalSum =mainuser.getNowMoney().add(totalPrice);
            yxUserService.decPrice(mainuser.getUid(),totalPrice);
            yxUserBillService.expend4commission(mainuser.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_3.getValue(),totalPrice.doubleValue(),maintotalSum.doubleValue(), "积分抵扣",orderid);
            if(!isEmpty(team_com_commissionmap)){
                team_com_commissionmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }

            if(!isEmpty(team_com_pjmap)){
                team_com_pjmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }


        }

    }

    // 购买399面膜产品分润
    private  void yePayshlsOrder4mmNewCommission(String user_id, String goods_id,
                                              String member_level,String orderid, int amount,double price,String payment_id) {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        //省市级分润
        BigDecimal operateBigDecimal =new BigDecimal("2").multiply(new BigDecimal(amount));
        operateCommissionUpdate(orderid,operateBigDecimal);
        int pjSum =5;
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("1", "60");
        commissionSetting.put("2", "70");
        commissionSetting.put("3", "50");
        commissionSetting.put("4", "35");
        commissionSetting.put("5", "30");
        if (!isEmpty(commissionSetting)) {
            Map<String, String> team_com_commissionmap = new HashMap();
            Map<String, String> team_com_pjmap = new HashMap();//平级集合
            for(int i=0;i<amount;i++) {
                JSONObject main = new JSONObject();
                int orderCount =i+1;
                YxUser user = yxUserService.getById(Long.valueOf(user_id));
                YxStoreProduct product =productService.getById(Long.valueOf(goods_id));
                main.put("id", user_id);
                main.put("member_level", user.getLevel());
                JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                int index = 1;
                int level = 1;
                parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                Map<String, String> team_com_map = new HashMap();
                yePayuserSlimmingSale4mmCommissionUpdate(main, index, commissionSetting,
                        team_com_map, orderid, amount, new BigDecimal(price), payment_id,team_com_commissionmap,team_com_pjmap,pjSum);
                System.out.println("team_com_map：" + team_com_map);
                //userMgr.updateUser4slimVip(user_id);//更新购买399用户状态变化
                if(!"Y".equals(user.getWhetherVipSlim())){
                    if(orderCount ==amount){
                        if(product.getIsVip() ==1){
                            user = yxUserService.getById(Long.valueOf(user_id));
                            user.setWhetherVipSlim("Y");
                            user.setVipDate(new Date());
                            yxUserService.updateById(user);
                        }
                    }
                }
                Set<String> keySet = parentUsers.keySet();
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    String memberLevel =item.get("member_level").toString();
                    log.info("memberLevel====="+memberLevel);
                    int mLevel =0;
                    if(!isEmpty(memberLevel)){
                        mLevel =Integer.parseInt(memberLevel);
                    }
                    log.info("mLevel====="+mLevel);
                    log.info("level====="+level);
                    if(mLevel>=level) {
                        userSlimmingSale4mmCommissionUpdate(item, index, commissionSetting,
                                team_com_map, orderid, amount, team_com_commissionmap, team_com_pjmap, pjSum);
                        level =mLevel;
                    }
                    index++;
                }
                System.out.println("team_com_map1111111111：" + team_com_map);
                userMemberLevelUpdate(main, orderid, orderCount);
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    userMemberLevelUpdate(item, orderid, orderCount);
                }

            }

            YxUser mainuser =yxUserService.getById(Long.valueOf(user_id));
            BigDecimal totalPrice =new BigDecimal(price).multiply(new BigDecimal(amount)).setScale(2, BigDecimal.ROUND_UP);
            BigDecimal maintotalSum =mainuser.getNowMoney().add(totalPrice);
            yxUserService.decPrice(mainuser.getUid(),totalPrice);
            yxUserBillService.expend4commission(mainuser.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_3.getValue(),totalPrice.doubleValue(),maintotalSum.doubleValue(), "积分抵扣",orderid);
            if(!isEmpty(team_com_commissionmap)){
                team_com_commissionmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }

            if(!isEmpty(team_com_pjmap)){
                team_com_pjmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }
        }

    }

    // 购买618大礼包产品分润
    private  void yePayshlsOrder4lbNewCommission(String user_id, String goods_id,
                                                 String member_level,String orderid, int amount,double price,String payment_id) {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        //省市级分润
        BigDecimal operateBigDecimal =new BigDecimal("2").multiply(new BigDecimal(amount));
        operateCommissionUpdate(orderid,operateBigDecimal);
        int pjSum =5;
                JSONObject commissionSetting = new JSONObject();// 分润配置
                commissionSetting.put("1", "100");
                commissionSetting.put("2", "65");
                commissionSetting.put("3", "70");
                commissionSetting.put("4", "50");
                commissionSetting.put("5", "50");
                if (!isEmpty(commissionSetting)) {
                    Map<String, String> team_com_commissionmap = new HashMap();
                    Map<String, String> team_com_pjmap = new HashMap();//平级集合
                    for(int i=0;i<amount;i++) {
                        JSONObject main = new JSONObject();
                        YxStoreProduct product =productService.getById(Long.valueOf(goods_id));
                        int orderCount =0;
                        if(i ==0){
                            orderCount =product.getSingular();
                        }else{
                            orderCount =i*product.getSingular();
                        }
                        int count =i+1;//用于判断条件是否最后一个数量
                        YxUser user = yxUserService.getById(Long.valueOf(user_id));
                        main.put("id", user_id);
                        main.put("member_level", user.getLevel());
                        JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                        int index = 1;
                        int level = 1;
                        parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                        Map<String, String> team_com_map = new HashMap();
                        yePayuserSlimmingSale4mmCommissionUpdate(main, index, commissionSetting,
                                team_com_map, orderid, amount, new BigDecimal(price), payment_id,team_com_commissionmap,team_com_pjmap,pjSum);
                System.out.println("team_com_map：" + team_com_map);
                //userMgr.updateUser4slimVip(user_id);//更新购买399用户状态变化
                if(!"Y".equals(user.getWhetherVipSlim())){
                    if(count ==amount){
                        if(product.getIsVip() ==1){
                            user = yxUserService.getById(Long.valueOf(user_id));
                            user.setWhetherVipSlim("Y");
                            user.setVipDate(new Date());
                            yxUserService.updateById(user);
                        }
                    }
                }
                Set<String> keySet = parentUsers.keySet();
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    String memberLevel =item.get("member_level").toString();
                    log.info("memberLevel====="+memberLevel);
                    int mLevel =0;
                    if(!isEmpty(memberLevel)){
                        mLevel =Integer.parseInt(memberLevel);
                    }
                    log.info("mLevel====="+mLevel);
                    log.info("level====="+level);
                    if(mLevel>=level) {
                        userSlimmingSale4mmCommissionUpdate(item, index, commissionSetting,
                                team_com_map, orderid, amount, team_com_commissionmap, team_com_pjmap, pjSum);
                        level =mLevel;
                    }
                    index++;
                }
                System.out.println("team_com_map1111111111：" + team_com_map);
                userMemberLevelUpdate(main, orderid, orderCount);
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    userMemberLevelUpdate(item, orderid, orderCount);
                }

            }

            YxUser mainuser =yxUserService.getById(Long.valueOf(user_id));
            BigDecimal totalPrice =new BigDecimal(price).multiply(new BigDecimal(amount)).setScale(2, BigDecimal.ROUND_UP);
            BigDecimal maintotalSum =mainuser.getNowMoney().add(totalPrice);
            yxUserService.decPrice(mainuser.getUid(),totalPrice);
            yxUserBillService.expend4commission(mainuser.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_3.getValue(),totalPrice.doubleValue(),maintotalSum.doubleValue(), "积分抵扣",orderid);
            if(!isEmpty(team_com_commissionmap)){
                team_com_commissionmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }

            if(!isEmpty(team_com_pjmap)){
                team_com_pjmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }
        }

    }

    // 购买1618大礼包产品分润
    private  void yePayshlsOrder4dlbNewCommission(String user_id, String goods_id,
                                                 String member_level,String orderid, int amount,double price,String payment_id) {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        //省市级分润
        //BigDecimal operateBigDecimal =new BigDecimal("2").multiply(new BigDecimal(amount));
        //operateCommissionUpdate(orderid,operateBigDecimal);
        int pjSum =20;
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("1", "280");
        commissionSetting.put("2", "170");
        commissionSetting.put("3", "170");
        commissionSetting.put("4", "160");
        commissionSetting.put("5", "120");
        if (!isEmpty(commissionSetting)) {
            Map<String, String> team_com_commissionmap = new HashMap();
            Map<String, String> team_com_pjmap = new HashMap();//平级集合
            for(int i=0;i<amount;i++) {
                JSONObject main = new JSONObject();
                YxStoreProduct product =productService.getById(Long.valueOf(goods_id));
                int orderCount =0;
                if(i ==0){
                    orderCount =product.getSingular();
                }else{
                    orderCount =i*product.getSingular();
                }
                int count =i+1;//用于判断条件是否最后一个数量
                YxUser user = yxUserService.getById(Long.valueOf(user_id));
                main.put("id", user_id);
                main.put("member_level", user.getLevel());
                JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                int index = 1;
                int level = 1;
                parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                Map<String, String> team_com_map = new HashMap();
                yePayuserSlimmingSale4mmCommissionUpdate(main, index, commissionSetting,
                        team_com_map, orderid, amount, new BigDecimal(price), payment_id,team_com_commissionmap,team_com_pjmap,pjSum);
                System.out.println("team_com_map：" + team_com_map);
                //userMgr.updateUser4slimVip(user_id);//更新购买399用户状态变化
                if(!"Y".equals(user.getWhetherVipSlim())){
                    if(count ==amount){
                        if(product.getIsVip() ==1){
                            user = yxUserService.getById(Long.valueOf(user_id));
                            user.setWhetherVipSlim("Y");
                            user.setVipDate(new Date());
                            yxUserService.updateById(user);
                        }
                    }
                }
                Set<String> keySet = parentUsers.keySet();
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    String memberLevel =item.get("member_level").toString();
                    log.info("memberLevel====="+memberLevel);
                    int mLevel =0;
                    if(!isEmpty(memberLevel)){
                        mLevel =Integer.parseInt(memberLevel);
                    }
                    log.info("mLevel====="+mLevel);
                    log.info("level====="+level);
                    if(mLevel>=level) {
                        userSlimmingSale4mmCommissionUpdate(item, index, commissionSetting,
                                team_com_map, orderid, amount, team_com_commissionmap, team_com_pjmap, pjSum);
                        level =mLevel;
                    }
                    index++;
                }
                System.out.println("team_com_map1111111111：" + team_com_map);
                userMemberLevelUpdate(main, orderid, orderCount);
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    userMemberLevelUpdate(item, orderid, orderCount);
                }

            }

            YxUser mainuser =yxUserService.getById(Long.valueOf(user_id));
            BigDecimal totalPrice =new BigDecimal(price).multiply(new BigDecimal(amount)).setScale(2, BigDecimal.ROUND_UP);
            BigDecimal maintotalSum =mainuser.getNowMoney().add(totalPrice);
            yxUserService.decPrice(mainuser.getUid(),totalPrice);
            yxUserBillService.expend4commission(mainuser.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_3.getValue(),totalPrice.doubleValue(),maintotalSum.doubleValue(), "积分抵扣",orderid);
            if(!isEmpty(team_com_commissionmap)){
                team_com_commissionmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }

            if(!isEmpty(team_com_pjmap)){
                team_com_pjmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }
        }

    }

    // 余额购买2990大礼包产品分润
    private  void yePayshlsOrder4NewLiBaoCommission(String user_id, String goods_id,
                                                 String member_level,String orderid, int amount,double price,String payment_id) {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        //省市级分润
        BigDecimal operateBigDecimal =new BigDecimal("20").multiply(new BigDecimal(amount));
        operateCommissionUpdate(orderid,operateBigDecimal);
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("1", "600");
        commissionSetting.put("2", "400");
        commissionSetting.put("3", "350");
        commissionSetting.put("4", "250");
        commissionSetting.put("5", "250");
        if (!isEmpty(commissionSetting)) {
            Map<String, String> team_com_commissionmap = new HashMap();
            Map<String, String> team_com_pjmap = new HashMap();//平级集合
            for(int i=0;i<amount;i++) {
                JSONObject main = new JSONObject();
                int orderCount =i+1;
                YxUser user = yxUserService.getById(Long.valueOf(user_id));
                YxStoreProduct product =productService.getById(Long.valueOf(goods_id));
                main.put("id", user_id);
                main.put("member_level", user.getLevel());
                JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                int index = 1;
                int level = 1;
                parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                Map<String, String> team_com_map = new HashMap();
                yePayuserSlimmingSale4NewLiBaoCommissionUpdate(main, index, commissionSetting,
                        team_com_map, orderid, amount, new BigDecimal(price), payment_id,team_com_commissionmap,team_com_pjmap);
                System.out.println("team_com_map：" + team_com_map);
                //userMgr.updateUser4slimVip(user_id);//更新购买399用户状态变化
                /*if(!"Y".equals(user.getWhetherVipSlim())){
                    if(product.getIsVip() ==1){
                        user = yxUserService.getById(Long.valueOf(user_id));
                        user.setWhetherVipSlim("Y");
                        user.setVipDate(new Date());
                        yxUserService.updateById(user);
                    }
                }*/
                Set<String> keySet = parentUsers.keySet();
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    String memberLevel =item.get("member_level").toString();
                    log.info("memberLevel====="+memberLevel);
                    int mLevel =0;
                    if(!isEmpty(memberLevel)){
                        mLevel =Integer.parseInt(memberLevel);
                    }
                    log.info("mLevel====="+mLevel);
                    log.info("level====="+level);
                    if(mLevel>=level) {
                        userSlimmingSale4NewLiBaoCommissionUpdate(item, index, commissionSetting,
                                team_com_map, orderid, amount, team_com_commissionmap, team_com_pjmap);
                        level =mLevel;
                    }
                    index++;
                }
                System.out.println("team_com_map1111111111：" + team_com_map);
                userMemberLevelUpdate(main, orderid, orderCount);
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                /*item.put("id", item.get("id").toString());
                item.put("member_level", item.get("member_level").toString());*/
                    userMemberLevelUpdate(item, orderid, orderCount);
                }
            }

            YxUser mainuser =yxUserService.getById(Long.valueOf(user_id));
            BigDecimal totalPrice =new BigDecimal(price).multiply(new BigDecimal(amount)).setScale(2, BigDecimal.ROUND_UP);
            BigDecimal maintotalSum =mainuser.getNowMoney().add(totalPrice);
            yxUserService.decPrice(mainuser.getUid(),totalPrice);
            yxUserBillService.expend4commission(mainuser.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_3.getValue(),totalPrice.doubleValue(),maintotalSum.doubleValue(), "积分抵扣",orderid);
            if(!isEmpty(team_com_commissionmap)){
                team_com_commissionmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }

            if(!isEmpty(team_com_pjmap)){
                team_com_pjmap.forEach((key, value) -> {
                    YxUser user =yxUserService.getById(Long.valueOf(key));
                    yxUserService.incMoney(user.getUid(),new BigDecimal(value));
                    BigDecimal totalSum =user.getNowMoney().add(new BigDecimal(value));
                    yxUserBillService.income(user.getUid(),"7", BillDetailEnum.CATEGORY_1.getValue(),
                            BillDetailEnum.TYPE_2.getValue(),new BigDecimal(value).doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
                });
            }

        }

    }

    // 余额购买1390产品分润
    private  void yePayvipOrderCommission4Package(String user_id, String goods_id,
                                                        String member_level,String orderid, int amount,double price,String payment_id) {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("1", "200");
        commissionSetting.put("2", "100");
        commissionSetting.put("3", "100");
        commissionSetting.put("4", "100");
        commissionSetting.put("5", "100");
        if (!isEmpty(commissionSetting)) {
            for(int i=0;i<amount;i++){
                JSONObject main = new JSONObject();
                int orderCount =i+1;
                YxUser user = yxUserService.getById(Long.valueOf(user_id));
                main.put("id", user_id);
                main.put("member_level", user.getLevel());
                JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                int index = 1;
                int level = 1;
                parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                Map<String, String> team_com_map = new HashMap();
                yePayuserCommissionUpdate4Package(main, index, commissionSetting,
                        team_com_map, orderid, amount, new BigDecimal(price), payment_id);
                Set<String> keySet = parentUsers.keySet();
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                    String memberLevel =item.get("member_level").toString();
                    log.info("memberLevel====="+memberLevel);
                    int mLevel =0;
                    if(!isEmpty(memberLevel)){
                        mLevel =Integer.parseInt(memberLevel);
                    }
                    log.info("mLevel====="+mLevel);
                    log.info("level====="+level);
                    if(mLevel>=level) {
                        userCommissionUpdate4Package(item, index, commissionSetting,
                                team_com_map, orderid, amount);
                        level =mLevel;
                    }
                    index++;
                }
                userMemberLevelUpdate4Package(main, orderid, orderCount);
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                    userMemberLevelUpdate4Package(item, orderid, orderCount);
                }
            }

        }
    }

    // 余额购买免费产品产品分润
    private  void yePayPostageOrderCommission(String user_id, String goods_id,
                                                 String member_level,String orderid, int amount,double price,String payment_id) {
        YxUser user = yxUserService.getById(Long.valueOf(user_id));
        BigDecimal totalPrice =new BigDecimal(price);
        yxUserService.decPrice(user.getUid(),totalPrice);
        yxUserBillService.expend4commission(Long.parseLong(user_id),"7", BillDetailEnum.CATEGORY_1.getValue(),
                BillDetailEnum.TYPE_3.getValue(),totalPrice.doubleValue(),user.getNowMoney().doubleValue(), "积分抵扣",orderid);
        System.out.println(user.getLevel() + "级用户" + user_id
                + "：《积分抵扣》" + totalPrice.multiply(new BigDecimal(-1)) + "元");

    }

    // 余额购买邮费专卖产品产品分润(18块钱)
    /*private void yePayPostageOrderCommission(String user_id, String goods_id,
                                                    String member_level,String orderid, int amount,double price,String payment_id) {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("2", "0.5");
        commissionSetting.put("3", "0.5");
        commissionSetting.put("4", "0.5");
        commissionSetting.put("5", "0.5");
        commissionSetting.put("6", "0.5");
        if (!ObjectUtil.isEmpty(commissionSetting)) {
            JSONObject main = new JSONObject();
            main.put("id", user_id);
            main.put("member_level", member_level);
            int index = 1;
            System.out.println("member_level==========="+member_level);
            JSONObject parentUsers = userMgr.getParentUsers4UnPeer(user_id,member_level);
            System.out.println("parentUsers==========="+parentUsers);
            //parentUsers = userMgr.getParentUsers(user_id);
            Map<String, String> team_com_map = new HashMap();
            Map<String, String> team_map = new HashMap();
            yePayuserPostageCommissionUpdate(main, index, commissionSetting,
                    team_com_map,orderid,amount,new BigDecimal(price),payment_id);
								*//*for (Iterator it = parentUsers.keys(); it.hasNext();) {
									String key = it.next().toString();
									JSONObject item = parentUsers.getJSONObject(key);
									String main_member_level = item.get("member_level").toString();
									if(!team_map.containsKey(main_member_level)){
										userPostageCommissionUpdate(item, index, commissionSetting,
												team_com_map,orderid,amount);
										team_map.put(main_member_level, "Y");
										index++;
									}
								}*//*
								*//*userMemberLevelUpdate(main);
								for (Iterator it = parentUsers.keys(); it.hasNext();) {
									String key = it.next().toString();
									JSONObject item = parentUsers.getJSONObject(key);
									userMemberLevelUpdate(item);
								}*//*


        }
    }*/

    // 购买1390套餐产品分润
    private  void vipOrderCommission4Package(String user_id, String goods_id,
                                                   String member_level,String orderid, int amount) {
        //JSONObject commissionSetting = userMgr.getCommissionSetting(goods_id);// 分润配置
        JSONObject commissionSetting = new JSONObject();// 分润配置
        commissionSetting.put("1", "200");
        commissionSetting.put("2", "100");
        commissionSetting.put("3", "100");
        commissionSetting.put("4", "100");
        commissionSetting.put("5", "100");
        if (!isEmpty(commissionSetting)) {
            for(int i=0;i<amount;i++) {
                JSONObject main = new JSONObject();
                int orderCount = i + 1;
                main.put("id", user_id);
                main.put("member_level", member_level);
                JSONObject parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                int index = 1;
                int level = 1;
                parentUsers = yxUserService.getParentUsers(Long.valueOf(user_id));
                Map<String, String> team_com_map = new HashMap();
                userCommissionUpdate4Package(main, index, commissionSetting,
                        team_com_map, orderid, amount);
                Set<String> keySet = parentUsers.keySet();
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                    String memberLevel =item.get("member_level").toString();
                    log.info("memberLevel====="+memberLevel);
                    int mLevel =0;
                    if(!isEmpty(memberLevel)){
                        mLevel =Integer.parseInt(memberLevel);
                    }
                    log.info("mLevel====="+mLevel);
                    log.info("level====="+level);
                    if(mLevel>=level) {
                        userCommissionUpdate4Package(item, index, commissionSetting,
                                team_com_map, orderid, amount);
                        level =mLevel;
                    }
                    index++;
                }
                userMemberLevelUpdate4Package(main, orderid, orderCount);
                for (String key : keySet) {
                    //String key = it.next().toString();
                    JSONObject item = parentUsers.getJSONObject(key);
                    userMemberLevelUpdate4Package(item, orderid, orderCount);
                }
            }

        }
    }

    // 用户分润
    private  void userCommissionUpdate(JSONObject mainUser, int index,
                                             JSONObject commissionSetting, Map<String, String> team_com_map,String orderid, int amount,Map<String, String> team_com_commissionmap)
             {
        String mainUserId = mainUser.get("id").toString();
        String main_member_level = mainUser.get("member_level").toString();
        YxUser user = yxUserService.getById(Long.valueOf(mainUserId));
        System.out.println("mainUserId==========="+mainUserId+"=======main_member_level===="+main_member_level+"=======amount===="+amount);
        if (main_member_level.equals("0")) {
            System.out.println("普通用户：" + mainUserId + "无分润权限");
            return;
        }
        if (!"Y".equals(user.getWhetherVipSlim())) {
            System.out.println("用户：" + mainUserId + "未购买vip礼包产品,无分润权限");
            return;
        }
        int commissionSum = 0;
        for(int i = Integer.parseInt(main_member_level);i>0;i--) {
            if(i == 5 && team_com_map.containsKey("5") && team_com_map.get("5").equals("Y")) {
                commissionSum = 1;
                team_com_map.put("5", "N");
                break;
            }
            if(!team_com_map.containsKey(String.valueOf(i))) {
                System.out.println("=======commissionSum1111===="+commissionSum+"=======commissionSetting===="+commissionSetting.getInteger(String.valueOf(i)));
                commissionSum += (commissionSetting.getInteger(String.valueOf(i)));
                team_com_map.put(String.valueOf(i), "Y");
            }
        }

        System.out.println("team_com_map==========="+team_com_map+"=======commissionSetting===="+commissionSetting+"=======commissionSum===="+commissionSum);
        if(commissionSum>0) {
            BigDecimal commissionTotalSum =new BigDecimal(commissionSum).setScale(2, BigDecimal.ROUND_UP);
            if(team_com_commissionmap.containsKey(mainUserId)) {
                BigDecimal tempSum =new BigDecimal(team_com_commissionmap.get(mainUserId)).add(commissionTotalSum);
                team_com_commissionmap.put(mainUserId, tempSum.toString());
            }else{
                team_com_commissionmap.put(mainUserId, commissionTotalSum.toString());
            }
            /*BigDecimal commissionTotalSum =new BigDecimal(commissionSum).setScale(2, BigDecimal.ROUND_UP);
            System.out.println("commissionTotalSum=================================="+commissionTotalSum);
            BigDecimal balance_sum =(commissionTotalSum.multiply(new BigDecimal("0.1"))).setScale(2, BigDecimal.ROUND_UP);//付存余额
            BigDecimal totalSum =(commissionTotalSum.multiply(new BigDecimal("0.9"))).setScale(2, BigDecimal.ROUND_UP);//利润余额
*/
            /*BigDecimal userTotalSum =user.getNowMoney().add(new BigDecimal(commissionSum));
            yxUserBillService.income(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),new BigDecimal(commissionSum).doubleValue(),userTotalSum.doubleValue(), "订单分润",orderid);
            yxUserService.incMoney(Long.parseLong(mainUserId),new BigDecimal(commissionSum));*/
            //yxUserService.incBrokeragePrice(new BigDecimal(commissionSum),Long.parseLong(mainUserId));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《提成》" + new BigDecimal(commissionSum) + "元");
        }
    }

    // 用户分润
    private  void userPostageCommissionUpdate(JSONObject mainUser, int index,
                                                    JSONObject commissionSetting, Map<String, String> team_com_map,String orderid, int amount)
             {
        String mainUserId = mainUser.get("id").toString();
        String main_member_level = mainUser.get("member_level").toString();
        YxUser user = yxUserService.getById(Long.valueOf(mainUserId));
        System.out.println("mainUserId==========="+mainUserId+"=======main_member_level===="+main_member_level+"=======amount===="+amount);
        if (main_member_level.equals("0")) {
            System.out.println("普通用户：" + mainUserId + "无分润权限");
            return;
        }
                 if (!"Y".equals(user.getWhetherVipSlim())) {
                     System.out.println("用户：" + mainUserId + "未购买vip礼包产品,无分润权限");
                     return;
                 }
        BigDecimal commissionSum = new BigDecimal("0");

        //System.out.println("=======commissionSum1111===="+commissionSum+"=======commissionSetting===="+commissionSetting.getInt(String.valueOf(i)));
        commissionSum = new BigDecimal(commissionSetting.getString(String.valueOf(main_member_level))).multiply(new BigDecimal(amount));
        //team_com_map.put(String.valueOf(i), "Y");


        System.out.println("team_com_map==========="+team_com_map+"=======commissionSetting===="+commissionSetting+"=======commissionSum===="+commissionSum);
        if(commissionSum.compareTo(new BigDecimal("0")) !=-1) {
            BigDecimal commissionTotalSum =commissionSum.setScale(2, BigDecimal.ROUND_UP);
            System.out.println("commissionTotalSum=================================="+commissionTotalSum);
            BigDecimal balance_sum =(commissionTotalSum.multiply(new BigDecimal("0.1"))).setScale(2, BigDecimal.ROUND_UP);//付存余额
            BigDecimal totalSum =(commissionTotalSum.multiply(new BigDecimal("0.9"))).setScale(2, BigDecimal.ROUND_UP);//利润余额

            yxUserBillService.income(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),totalSum.doubleValue(),user.getNowMoney().doubleValue(), "订单分润",orderid);
            yxUserService.incMoney(Long.parseLong(mainUserId),totalSum);
            //yxUserService.incBrokeragePrice(totalSum,Long.parseLong(mainUserId));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《提成》" + totalSum + "元");
            yxUserBillService.income(Long.parseLong(mainUserId),"11", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),balance_sum.doubleValue(),user.getBalanceSum().doubleValue(), "订单分润",orderid);
            yxUserService.incBalancePrice(balance_sum,Long.parseLong(mainUserId));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《复购提成》" + balance_sum + "元");
				/*Commission c1= new Commission();
				c1.setCommission_sum(new BigDecimal(commissionSum));
				c1.setCommission_type("7");
				c1.setOrder_id(Long.parseLong(orderid));
				c1.setUser_id(Long.parseLong(mainUserId));
				commissionMgr.addNew(c1);
				System.out.println(main_member_level + "级用户" + mainUserId
						+ "：《提成》" + commissionSum + "元");*/
        }
    }



    // 399瘦身活动用户分润
    private  void userSlimmingCommissionUpdate(JSONObject mainUser, int index,
                                                     JSONObject commissionSetting, Map<String, String> team_com_map,String orderid, int amount)
             {
        String mainUserId = mainUser.get("id").toString();
        String main_member_level = mainUser.get("member_level").toString();
        String main_whether_slim = mainUser.get("whether_slim").toString();
        YxUser user = yxUserService.getById(Long.valueOf(mainUserId));
        if (main_member_level.equals("0")) {
            System.out.println("普通用户：" + mainUserId + "无分润权限");
            return;
        }
        /*if (!main_whether_slim.equals("1")) {
            System.out.println("用户：" + mainUserId + "未购买瘦身活动,无分润权限");
            return;
        }*/
                 if (!"Y".equals(user.getWhetherVipSlim())) {
                     System.out.println("用户：" + mainUserId + "未购买vip礼包产品,无分润权限");
                     return;
                 }
        int commissionSum = 0;
        for(int i = Integer.parseInt(main_member_level);i>0;i--) {
            if(i == 5 && team_com_map.containsKey("5") && team_com_map.get("5").equals("Y")) {
                commissionSum = 5 * amount;
                team_com_map.put("5", "N");
                break;
            }
            if(!team_com_map.containsKey(String.valueOf(i))) {
                commissionSum += (commissionSetting.getInteger(String.valueOf(i))*amount);
                team_com_map.put(String.valueOf(i), "Y");
            }
        }


        if(commissionSum>0) {
            BigDecimal commissionTotalSum =new BigDecimal(commissionSum).setScale(2, BigDecimal.ROUND_UP);
            System.out.println("commissionTotalSum=================================="+commissionTotalSum);
            BigDecimal balance_sum =(commissionTotalSum.multiply(new BigDecimal("0.1"))).setScale(2, BigDecimal.ROUND_UP);//付存余额
            BigDecimal totalSum =(commissionTotalSum.multiply(new BigDecimal("0.9"))).setScale(2, BigDecimal.ROUND_UP);//利润余额

            yxUserBillService.income(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),totalSum.doubleValue(),user.getNowMoney().doubleValue(), "订单分润",orderid);
            yxUserService.incMoney(Long.parseLong(mainUserId),totalSum);
            //yxUserService.incBrokeragePrice(totalSum,Long.parseLong(mainUserId));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《提成》" + totalSum + "元");
            yxUserBillService.income(Long.parseLong(mainUserId),"11", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),balance_sum.doubleValue(),user.getBalanceSum().doubleValue(), "订单分润",orderid);
            yxUserService.incBalancePrice(balance_sum,Long.parseLong(mainUserId));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《复购提成》" + balance_sum + "元");
				/*Commission c1= new Commission();
				c1.setCommission_sum(new BigDecimal(commissionSum));
				c1.setCommission_type("7");
				c1.setOrder_id(Long.parseLong(orderid));
				c1.setUser_id(Long.parseLong(mainUserId));
				commissionMgr.addNew(c1);
				System.out.println(main_member_level + "级用户" + mainUserId
						+ "：《提成》" + commissionSum + "元");*/
        }
    }

    // 299瘦身零售用户分润
    private  void userSlimmingSaleCommissionUpdate(JSONObject mainUser, int index,
                                                         JSONObject commissionSetting, Map<String, String> team_com_map,String orderid, int amount)
             {
        String mainUserId = mainUser.get("id").toString();
        String main_member_level = mainUser.get("member_level").toString();
        //String main_whether_slim = mainUser.get("whether_slim").toString();
         YxUser user = yxUserService.getById(Long.valueOf(mainUserId));
        if (main_member_level.equals("0")) {
            System.out.println("普通用户：" + mainUserId + "无分润权限");
            return;
        }
                 if (!"Y".equals(user.getWhetherVipSlim())) {
                     System.out.println("用户：" + mainUserId + "未购买vip礼包产品,无分润权限");
                     return;
                 }
					/*if (!main_whether_slim.equals("1")) {
						System.out.println("用户：" + mainUserId + "未购买瘦身活动,无分润权限");
						return;
					}*/
        int commissionSum = 0;
        for(int i = Integer.parseInt(main_member_level);i>0;i--) {
            if(i == 5 && team_com_map.containsKey("5") && team_com_map.get("5").equals("Y")) {
                commissionSum = 5 * amount;
                team_com_map.put("5", "N");
                break;
            }
            if(!team_com_map.containsKey(String.valueOf(i))) {
                commissionSum += (commissionSetting.getInteger(String.valueOf(i))*amount);
                team_com_map.put(String.valueOf(i), "Y");
            }
        }


        if(commissionSum>0) {
            BigDecimal commissionTotalSum =new BigDecimal(commissionSum).setScale(2, BigDecimal.ROUND_UP);
            System.out.println("commissionTotalSum=================================="+commissionTotalSum);
            BigDecimal balance_sum =(commissionTotalSum.multiply(new BigDecimal("0.1"))).setScale(2, BigDecimal.ROUND_UP);//付存余额
            BigDecimal totalSum =(commissionTotalSum.multiply(new BigDecimal("0.9"))).setScale(2, BigDecimal.ROUND_UP);//利润余额

            yxUserBillService.income(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),totalSum.doubleValue(),user.getNowMoney().doubleValue(), "订单分润",orderid);
            yxUserService.incMoney(Long.parseLong(mainUserId),totalSum);
            yxUserService.incBrokeragePrice(totalSum,Long.parseLong(mainUserId));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《提成》" + totalSum + "元");
            yxUserBillService.income(Long.parseLong(mainUserId),"11", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),balance_sum.doubleValue(),user.getBalanceSum().doubleValue(), "订单分润",orderid);
            yxUserService.incBalancePrice(balance_sum,Long.parseLong(mainUserId));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《复购提成》" + balance_sum + "元");
						/*Commission c1= new Commission();
						c1.setCommission_sum(new BigDecimal(commissionSum));
						c1.setCommission_type("7");
						c1.setOrder_id(Long.parseLong(orderid));
						c1.setUser_id(Long.parseLong(mainUserId));
						commissionMgr.addNew(c1);
						System.out.println(main_member_level + "级用户" + mainUserId
								+ "：《提成》" + commissionSum + "元");*/
        }
    }

    // 299面膜产品用户分润
    private  void userSlimmingSale4mmCommissionUpdate(JSONObject mainUser, int index,
                                                            JSONObject commissionSetting, Map<String, String> team_com_map,String orderid, int amount,Map<String, String> team_com_commissionmap,Map<String, String> team_com_pjmap,int pjSum)
             {
        String mainUserId = mainUser.get("id").toString();
        String main_member_level = mainUser.get("member_level").toString();
        YxUser user = yxUserService.getById(Long.valueOf(mainUserId));
        //String vipcount = storeOrderCartInfoService.getOrderVIPCountByUserid(Long.valueOf(mainUserId));//检查是否有购买299产品
        //System.out.println("vipcount=======" + vipcount );
        //String main_whether_slim = mainUser.get("whether_slim").toString();
        if (main_member_level.equals("0")) {
            System.out.println("普通用户：" + mainUserId + "无分润权限");
            return;
        }
        /*if (isEmpty(vipcount) ||Integer.parseInt(vipcount)<1) {
            System.out.println("用户：" + mainUserId + "未购买299礼包,无分润权限");
            return;
        }*/
         if (!"Y".equals(user.getWhetherVipSlim())) {
             System.out.println("用户：" + mainUserId + "未购买vip礼包产品,无分润权限");
              return;
         }
        int commissionSum = 0;
        int pj_commissionSum = 0;
        //int pj_sum =5*(amount);
        int pj_sum =pjSum;
        YxUser parentUser =new YxUser();
        String hasParent ="N";

        log.info("用户的可用余额NowMoney====="+user.getNowMoney());
        JSONObject jsonObj = yxUserService.getParentByUserid(Long.valueOf(mainUserId),Integer.valueOf(main_member_level));
        //JSONObject jsonObj = userMgr.getParentByUserid(mainUserId,main_member_level);
        System.out.println("11111111111111");
        String parent_id = jsonObj.getString("parent_id");
        String member_id = jsonObj.getString("member_id");
        System.out.println("parent_id用户：" + parent_id+"-------------member_id"+member_id);
        //System.out.println("用户user id+等级：" +user.getId()+"-----"+ user.getMember_id().intValue() );
        //System.out.println("用户user Kf_code：" +user.getKf_code() );
        if(!isEmpty(parent_id)){
            if(user.getSpreadUid().intValue() !=0){
                parentUser =yxUserService.getById(user.getSpreadUid());
                if(parentUser.getLevel() <=Integer.parseInt(member_id)){
                    hasParent ="Y";
                }
            }
            System.out.println( "上级parentUser id+等级"+parent_id+"-----"+Integer.parseInt(member_id));
        }
        //System.out.println("用户user Kf_code1111111  team_com_map" +team_com_map.get("6") );
        for(int i = Integer.parseInt(main_member_level);i>0;i--) {
            if(i == 5 && team_com_map.containsKey("5") && team_com_map.get("5").equals("Y")) {
                System.out.println("只有一次:用户user id+等级：" +user.getUid()+"-----"+ user.getLevel() );
                //commissionSum = 5 * (amount/5);
                pj_commissionSum = 5;
                team_com_map.put("5", "N");
                break;
            }
            if(!team_com_map.containsKey(String.valueOf(i))) {
                commissionSum += (commissionSetting.getInteger(String.valueOf(i)));
                team_com_map.put(String.valueOf(i), "Y");
            }
        }
        //System.out.println("用户  parentUser22222  user 的commissionSum====" +commissionSum );
        if("Y".equals(hasParent)&&commissionSum>0){
            System.out.println("用户user等级：" + user.getLevel().intValue() +"==上级用户parentUser等级"+member_id);
            if(user.getLevel().intValue()>=3&&(user.getLevel().intValue() ==Integer.parseInt(member_id))){
                commissionSum =commissionSum-pj_sum;
                pj_commissionSum =pj_sum;
                System.out.println("用户user等级>=钻石并且上级是同级：" + user.getLevel().intValue() +"===用户user commissionSum="+commissionSum+"===用户parentUser pj_commissionSum="+pj_commissionSum);
            }
        }
        //System.out.println("用户 3333====" +commissionSum );
        if(commissionSum>0) {
            log.info("commissionSum====="+commissionSum);
            BigDecimal commissionTotalSum =new BigDecimal(commissionSum);
            //System.out.println("commissionTotalSum=================================="+commissionTotalSum);
						/*BigDecimal balance_sum =(commissionTotalSum.multiply(new BigDecimal("0.1"))).setScale(2, BigDecimal.ROUND_UP);//付存余额
						BigDecimal totalSum =(commissionTotalSum.multiply(new BigDecimal("0.9"))).setScale(2, BigDecimal.ROUND_UP);//利润余额*/
            log.info("commissionTotalSum======"+commissionTotalSum);
            log.info("mainUserId======"+mainUserId);
            log.info("NowMoney======"+user.getNowMoney());
           /* yxUserService.incMoney(Long.parseLong(mainUserId),commissionTotalSum);
            YxUser userTemp = yxUserService.getById(Long.valueOf(mainUserId));
            log.info("更新后的NowMoney======"+userTemp.getNowMoney());
            //yxUserService.incBrokeragePrice(commissionTotalSum,Long.parseLong(mainUserId));
            BigDecimal totalSum =user.getNowMoney().add(commissionTotalSum);
            yxUserBillService.income(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),commissionTotalSum.doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《提成》" + commissionTotalSum + "元");
            YxUser userTemp1 = yxUserService.getById(Long.valueOf(mainUserId));
            log.info("更新后userTemp1的NowMoney======"+userTemp1.getNowMoney());*/
            if(team_com_commissionmap.containsKey(mainUserId)) {
                BigDecimal tempSum =new BigDecimal(team_com_commissionmap.get(mainUserId)).add(commissionTotalSum);
                team_com_commissionmap.put(mainUserId, tempSum.toString());
            }else{
                team_com_commissionmap.put(mainUserId, commissionTotalSum.toString());
            }
            if(pj_commissionSum>0) {
               // YxUser parentuser = yxUserService.getById(Long.valueOf(parent_id));
                BigDecimal pj_commissionTotalSum =new BigDecimal(pj_commissionSum);
                System.out.println("pj_commissionTotalSum=================================="+pj_commissionTotalSum);
                if(team_com_pjmap.containsKey(parent_id)) {
                    String s =team_com_pjmap.get(parent_id);
                    BigDecimal tempSum =new BigDecimal(s).add(pj_commissionTotalSum);
                    team_com_pjmap.put(parent_id, tempSum.toString());
                }else{
                    team_com_pjmap.put(parent_id, pj_commissionTotalSum.toString());
                }
							/*BigDecimal pj_balance_sum =(pj_commissionTotalSum.multiply(new BigDecimal("0.1"))).setScale(2, BigDecimal.ROUND_UP);//付存余额
							BigDecimal pj_totalSum =(pj_commissionTotalSum.multiply(new BigDecimal("0.9"))).setScale(2, BigDecimal.ROUND_UP);//利润余额*/
                /*BigDecimal pj_totalSum =parentuser.getNowMoney().add(pj_commissionTotalSum);
                yxUserBillService.income(Long.parseLong(parent_id),"7", BillDetailEnum.CATEGORY_1.getValue(),
                        BillDetailEnum.TYPE_2.getValue(),pj_commissionTotalSum.doubleValue(),pj_totalSum.doubleValue(), "订单分润",orderid);
                yxUserService.incMoney(Long.parseLong(parent_id),pj_commissionTotalSum);
                //yxUserService.incBrokeragePrice(pj_commissionTotalSum,Long.parseLong(parent_id));
                System.out.println(main_member_level + "级用户平级奖" + parent_id
                        + "：《提成》" + pj_commissionTotalSum + "元");*/

            }
        }

    }

    // 2990面膜产品用户分润
    private  void userSlimmingSale4NewLiBaoCommissionUpdate(JSONObject mainUser, int index,
                                                      JSONObject commissionSetting,
                                                            Map<String, String> team_com_map,String orderid, int amount,Map<String, String> team_com_commissionmap,Map<String, String> team_com_pjmap)
    {
        String mainUserId = mainUser.get("id").toString();
        String main_member_level = mainUser.get("member_level").toString();
        //String vipcount = storeOrderCartInfoService.getOrderVIPCountByUserid(Long.valueOf(mainUserId));//检查是否有购买299产品
        //System.out.println("vipcount=======" + vipcount );
        //String main_whether_slim = mainUser.get("whether_slim").toString();
        YxUser user = yxUserService.getById(Long.valueOf(mainUserId));
        if (main_member_level.equals("0")) {
            System.out.println("普通用户：" + mainUserId + "无分润权限");
            return;
        }
        /*if (isEmpty(vipcount) ||Integer.parseInt(vipcount)<1) {
            System.out.println("用户：" + mainUserId + "未购买299礼包,无分润权限");
            return;
        }*/
        if (!"Y".equals(user.getWhetherVipSlim())) {
            System.out.println("用户：" + mainUserId + "未购买vip礼包产品,无分润权限");
            return;
        }
        int commissionSum = 0;
        int pj_commissionSum = 0;
        int pj_sum =50;
        YxUser parentUser =new YxUser();
        String hasParent ="N";

        log.info("用户的可用余额NowMoney====="+user.getNowMoney());
        JSONObject jsonObj = yxUserService.getParentByUserid(Long.valueOf(mainUserId),Integer.valueOf(main_member_level));
        //JSONObject jsonObj = userMgr.getParentByUserid(mainUserId,main_member_level);
        System.out.println("11111111111111");
        String parent_id = jsonObj.getString("parent_id");
        String member_id = jsonObj.getString("member_id");
        System.out.println("parent_id用户：" + parent_id+"-------------member_id"+member_id);
        //System.out.println("用户user id+等级：" +user.getId()+"-----"+ user.getMember_id().intValue() );
        //System.out.println("用户user Kf_code：" +user.getKf_code() );
        if(!isEmpty(parent_id)){
            //parentUser = userMgr.findById(user.getKf_code());
            //System.out.println( "上级parentUser等级"+parentUser.getMember_id().intValue());
            if(user.getSpreadUid().intValue() !=0){
                parentUser =yxUserService.getById(user.getSpreadUid());
                if(parentUser.getLevel() <=Integer.parseInt(member_id)){
                    hasParent ="Y";
                }
            }
        }
        //System.out.println("用户user Kf_code1111111  team_com_map" +team_com_map.get("6") );
        for(int i = Integer.parseInt(main_member_level);i>0;i--) {
            if(i == 5 && team_com_map.containsKey("5") && team_com_map.get("5").equals("Y")) {
                System.out.println("只有一次:用户user id+等级：" +user.getUid()+"-----"+ user.getLevel() );
                //commissionSum = 5 * (amount/5);
                pj_commissionSum = 50;
                team_com_map.put("5", "N");
                break;
            }
            if(!team_com_map.containsKey(String.valueOf(i))) {
                commissionSum += (commissionSetting.getInteger(String.valueOf(i)));
                team_com_map.put(String.valueOf(i), "Y");
            }
        }
        //System.out.println("用户  parentUser22222  user 的commissionSum====" +commissionSum );
        if("Y".equals(hasParent)&&commissionSum>0){
            System.out.println("用户user等级：" + user.getLevel().intValue() +"==上级用户parentUser等级"+member_id);
            if(user.getLevel().intValue()>=3&&(user.getLevel().intValue() ==Integer.parseInt(member_id))){
                commissionSum =commissionSum-pj_sum;
                pj_commissionSum =pj_sum;
                System.out.println("用户user等级>=钻石并且上级是同级：" + user.getLevel().intValue() +"===用户user commissionSum="+commissionSum+"===用户parentUser pj_commissionSum="+pj_commissionSum);
            }
        }
        //System.out.println("用户 3333====" +commissionSum );
        if(commissionSum>0) {
            BigDecimal commissionTotalSum =new BigDecimal(commissionSum);
            if(team_com_commissionmap.containsKey(mainUserId)) {
                BigDecimal tempSum =new BigDecimal(team_com_commissionmap.get(mainUserId)).add(commissionTotalSum);
                team_com_commissionmap.put(mainUserId, tempSum.toString());
            }else{
                team_com_commissionmap.put(mainUserId, commissionTotalSum.toString());
            }
            //System.out.println("commissionTotalSum=================================="+commissionTotalSum);
						/*BigDecimal balance_sum =(commissionTotalSum.multiply(new BigDecimal("0.1"))).setScale(2, BigDecimal.ROUND_UP);//付存余额
						BigDecimal totalSum =(commissionTotalSum.multiply(new BigDecimal("0.9"))).setScale(2, BigDecimal.ROUND_UP);//利润余额*/
           /* yxUserService.incMoney(Long.parseLong(mainUserId),commissionTotalSum);
            //yxUserService.incBrokeragePrice(commissionTotalSum,Long.parseLong(mainUserId));
            BigDecimal totalSum =user.getNowMoney().add(commissionTotalSum);
            yxUserBillService.income(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),commissionTotalSum.doubleValue(),totalSum.doubleValue(), "订单分润",orderid);
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《提成》" + commissionTotalSum + "元");*/

            if(pj_commissionSum>0) {
                YxUser parentuser = yxUserService.getById(Long.valueOf(parent_id));
                BigDecimal pj_commissionTotalSum =new BigDecimal(pj_commissionSum);
                System.out.println("pj_commissionTotalSum=================================="+pj_commissionTotalSum);
                if(team_com_pjmap.containsKey(parent_id)) {
                    String s =team_com_pjmap.get(parent_id);
                    BigDecimal tempSum =new BigDecimal(s).add(pj_commissionTotalSum);
                    team_com_pjmap.put(parent_id, tempSum.toString());
                }else{
                    team_com_pjmap.put(parent_id, pj_commissionTotalSum.toString());
                }
                /*BigDecimal pj_totalSum =parentuser.getNowMoney().add(pj_commissionTotalSum);
                yxUserBillService.income(Long.parseLong(parent_id),"7", BillDetailEnum.CATEGORY_1.getValue(),
                        BillDetailEnum.TYPE_2.getValue(),pj_commissionTotalSum.doubleValue(),pj_totalSum.doubleValue(), "订单分润",orderid);
                yxUserService.incMoney(Long.parseLong(parent_id),pj_commissionTotalSum);
                //yxUserService.incBrokeragePrice(pj_commissionTotalSum,Long.parseLong(parent_id));
                System.out.println(main_member_level + "级用户平级奖" + parent_id
                        + "：《提成》" + pj_commissionTotalSum + "元");*/

            }
        }

    }

    // 用户余额支付分润
    private  void yePayuserCommissionUpdate(JSONObject mainUser, int index,
                                                  JSONObject commissionSetting, Map<String, String> team_com_map,String orderid, int amount,BigDecimal totalPrice,String payment_id,Map<String, String> team_com_commissionmap)
            {
        String mainUserId = mainUser.get("id").toString();
        String main_member_level = mainUser.get("member_level").toString();
        totalPrice =totalPrice.setScale(2, BigDecimal.ROUND_UP);
        YxUser user = yxUserService.getById(Long.valueOf(mainUserId));
            /*yxUserService.decPrice(Long.parseLong(mainUserId),totalPrice);
            user = yxUserService.getById(Long.valueOf(mainUserId));
            yxUserBillService.expend4commission(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_3.getValue(),totalPrice.doubleValue(),user.getNowMoney().doubleValue(), "积分抵扣",orderid);
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《积分抵扣》" + totalPrice + "元");*/
        if (main_member_level.equals("0")) {
            System.out.println("普通用户：" + mainUserId + "无分润权限");
            return;
        }
        if (!"Y".equals(user.getWhetherVipSlim())) {
            System.out.println("用户：" + mainUserId + "未购买vip礼包产品,无分润权限");
            return;
        }
        int commissionSum = 0;
        for(int i = Integer.parseInt(main_member_level);i>0;i--) {
            if(i == 5 && team_com_map.containsKey("5") && team_com_map.get("5").equals("Y")) {
                commissionSum = 1;
                team_com_map.put("5", "N");
                break;
            }
            if(!team_com_map.containsKey(String.valueOf(i))) {
                commissionSum += (commissionSetting.getInteger(String.valueOf(i)));
                team_com_map.put(String.valueOf(i), "Y");
            }
        }


        if(commissionSum>0) {
            BigDecimal commissionTotalSum =new BigDecimal(commissionSum);
            if(team_com_commissionmap.containsKey(mainUserId)) {
                BigDecimal tempSum =new BigDecimal(team_com_commissionmap.get(mainUserId)).add(commissionTotalSum);
                team_com_commissionmap.put(mainUserId, tempSum.toString());
            }else{
                team_com_commissionmap.put(mainUserId, commissionTotalSum.toString());
            }
            /*BigDecimal commissionTotalSum =new BigDecimal(commissionSum).setScale(2, BigDecimal.ROUND_UP);
           /* user = yxUserService.getById(Long.valueOf(mainUserId));
            BigDecimal userTotalSum =user.getNowMoney().add(new BigDecimal(commissionSum));
            yxUserBillService.income(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),new BigDecimal(commissionSum).doubleValue(),userTotalSum.doubleValue(), "订单分润",orderid);
            yxUserService.incMoney(Long.parseLong(mainUserId),new BigDecimal(commissionSum));
            //yxUserService.incBrokeragePrice(new BigDecimal(commissionSum),Long.parseLong(mainUserId));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《提成》" + new BigDecimal(commissionSum) + "元");*/

        }

    }

    // 用户余额支付分润
    private  void yePayuserPostageCommissionUpdate(JSONObject mainUser, int index,
                                                         JSONObject commissionSetting, Map<String, String> team_com_map,String orderid, int amount,BigDecimal totalPrice,String payment_id)
            {
        String mainUserId = mainUser.get("id").toString();
        String main_member_level = mainUser.get("member_level").toString();
        totalPrice =totalPrice.setScale(2, BigDecimal.ROUND_UP);
        YxUser user = yxUserService.getById(Long.valueOf(mainUserId));
        if("yue".equals(payment_id)){
            /*Commission c1= new Commission();
            c1.setCommission_sum(totalPrice.multiply(new BigDecimal(-1)));
            c1.setCommission_type("7");
            c1.setOrder_id(Long.parseLong(orderid));
            c1.setUser_id(Long.parseLong(mainUserId));
            c1.setRemark("积分抵扣");
            commissionMgr.addNew(c1);*/
            yxUserBillService.expend4commission(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_3.getValue(),totalPrice.doubleValue(),user.getNowMoney().doubleValue(), "积分抵扣",orderid);
            yxUserService.incMoney(Long.parseLong(mainUserId),totalPrice.multiply(new BigDecimal(-1)));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《积分抵扣》" + totalPrice + "元");
        }else{
            /*Commission c1= new Commission();
            c1.setCommission_sum(totalPrice.multiply(new BigDecimal(-1)));
            c1.setCommission_type("11");
            c1.setOrder_id(Long.parseLong(orderid));
            c1.setUser_id(Long.parseLong(mainUserId));
            c1.setRemark("复购支付金额");
            commissionMgr.addNewBalance(c1);*/
            yxUserBillService.expend4commission(Long.parseLong(mainUserId),"11", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_3.getValue(),totalPrice.doubleValue(),user.getBalanceSum().doubleValue(), "复购支付金额",orderid);
            yxUserService.incBalancePrice(totalPrice.multiply(new BigDecimal(-1)),Long.parseLong(mainUserId));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《复购支付金额》" + totalPrice + "元");
        }


    }

    // 399瘦身活动用户分润
    private  void yePayuserSlimmingCommissionUpdate(JSONObject mainUser, int index,
                                                          JSONObject commissionSetting, Map<String, String> team_com_map,String orderid, int amount,BigDecimal totalPrice,String payment_id)
    {
        String mainUserId = mainUser.get("id").toString();
        String main_member_level = mainUser.get("member_level").toString();
        String main_whether_slim = mainUser.get("whether_slim").toString();
        totalPrice =totalPrice.setScale(2, BigDecimal.ROUND_UP);
        YxUser user = yxUserService.getById(Long.valueOf(mainUserId));
        if("yue".equals(payment_id)){
            /*Commission c1= new Commission();
            c1.setCommission_sum(totalPrice.multiply(new BigDecimal(-1)));
            c1.setCommission_type("7");
            c1.setOrder_id(Long.parseLong(orderid));
            c1.setUser_id(Long.parseLong(mainUserId));
            c1.setRemark("积分抵扣");
            commissionMgr.addNew(c1);*/
            yxUserService.decPrice(Long.parseLong(mainUserId),totalPrice);
            user = yxUserService.getById(Long.valueOf(mainUserId));
            yxUserBillService.expend4commission(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_3.getValue(),totalPrice.doubleValue(),user.getNowMoney().doubleValue(), "积分抵扣",orderid);
            //yxUserService.incMoney(Long.parseLong(mainUserId),totalPrice.multiply(new BigDecimal(-1)));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《积分抵扣》" + totalPrice.multiply(new BigDecimal(-1)) + "元");
        }else{
            /*Commission c1= new Commission();
            c1.setCommission_sum(totalPrice.multiply(new BigDecimal(-1)));
            c1.setCommission_type("11");
            c1.setOrder_id(Long.parseLong(orderid));
            c1.setUser_id(Long.parseLong(mainUserId));
            c1.setRemark("复购支付金额");
            commissionMgr.addNewBalance(c1);*/
            yxUserService.decBalancePrice(totalPrice,Long.parseLong(mainUserId));
            user = yxUserService.getById(Long.valueOf(mainUserId));
            yxUserBillService.expend4commission(Long.parseLong(mainUserId),"11", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_3.getValue(),totalPrice.doubleValue(),user.getBalanceSum().doubleValue(), "复购支付金额",orderid);
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《复购支付金额》" + totalPrice.multiply(new BigDecimal(-1)) + "元");
        }
        if (main_member_level.equals("0")) {
            System.out.println("普通用户：" + mainUserId + "无分润权限");
            return;
        }
        /*if (!main_whether_slim.equals("1")) {
            System.out.println("用户：" + mainUserId + "未购买瘦身活动,无分润权限");
            return;
        }*/
        if (!"Y".equals(user.getWhetherVipSlim())) {
            System.out.println("用户：" + mainUserId + "未购买vip礼包产品,无分润权限");
            return;
        }
        int commissionSum = 0;
        for(int i = Integer.parseInt(main_member_level);i>0;i--) {
            if(i == 5 && team_com_map.containsKey("5") && team_com_map.get("5").equals("Y")) {
                commissionSum = 5 * amount;
                team_com_map.put("5", "N");
                break;
            }
            if(!team_com_map.containsKey(String.valueOf(i))) {
                commissionSum += (commissionSetting.getInteger(String.valueOf(i))*amount);
                team_com_map.put(String.valueOf(i), "Y");
            }
        }


        if(commissionSum>0) {
            BigDecimal commissionTotalSum =new BigDecimal(commissionSum);
            System.out.println("commissionTotalSum=================================="+commissionTotalSum);
            /*BigDecimal balance_sum =(commissionTotalSum.multiply(new BigDecimal("0.1"))).setScale(2, BigDecimal.ROUND_UP);//付存余额
            BigDecimal totalSum =(commissionTotalSum.multiply(new BigDecimal("0.9"))).setScale(2, BigDecimal.ROUND_UP);//利润余额*/
            //YxUser user = yxUserService.getById(Long.valueOf(mainUserId));
            user = yxUserService.getById(Long.valueOf(mainUserId));
            BigDecimal usertotalSum =user.getNowMoney().add(commissionTotalSum);
            yxUserBillService.income(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),commissionTotalSum.doubleValue(),usertotalSum.doubleValue(), "订单分润",orderid);
            yxUserService.incMoney(Long.parseLong(mainUserId),commissionTotalSum);
            //yxUserService.incBrokeragePrice(totalSum,Long.parseLong(mainUserId));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《提成》" + commissionTotalSum + "元");
            /*BigDecimal userBalanceSum =user.getBalanceSum().add(balance_sum);
            yxUserBillService.income(Long.parseLong(mainUserId),"11", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),balance_sum.doubleValue(),userBalanceSum.doubleValue(), "订单分润",orderid);
            yxUserService.incBalancePrice(balance_sum,Long.parseLong(mainUserId));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《复购提成》" + balance_sum + "元");*/
        }
    }

    // 299瘦身零售用户分润
    private  void yePayuserSlimmingSaleCommissionUpdate(JSONObject mainUser, int index,
                                                              JSONObject commissionSetting, Map<String, String> team_com_map,String orderid, int amount,BigDecimal totalPrice,String payment_id)
            {
        String mainUserId = mainUser.get("id").toString();
        String main_member_level = mainUser.get("member_level").toString();
        totalPrice =totalPrice.setScale(2, BigDecimal.ROUND_UP);
        YxUser user = yxUserService.getById(Long.valueOf(mainUserId));
        if("yue".equals(payment_id)){
           /* Commission c1= new Commission();
            c1.setCommission_sum(totalPrice.multiply(new BigDecimal(-1)));
            c1.setCommission_type("7");
            c1.setOrder_id(Long.parseLong(orderid));
            c1.setUser_id(Long.parseLong(mainUserId));
            c1.setRemark("积分抵扣");
            commissionMgr.addNew(c1);*/
            yxUserBillService.expend4commission(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_3.getValue(),totalPrice.doubleValue(),user.getNowMoney().doubleValue(), "积分抵扣",orderid);
            yxUserService.incMoney(Long.parseLong(mainUserId),totalPrice.multiply(new BigDecimal(-1)));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《积分抵扣》" + totalPrice.multiply(new BigDecimal(-1)) + "元");
        }else{
            /*Commission c1= new Commission();
            c1.setCommission_sum(totalPrice.multiply(new BigDecimal(-1)));
            c1.setCommission_type("11");
            c1.setOrder_id(Long.parseLong(orderid));
            c1.setUser_id(Long.parseLong(mainUserId));
            c1.setRemark("复购支付金额");
            commissionMgr.addNewBalance(c1);*/
            yxUserBillService.expend4commission(Long.parseLong(mainUserId),"11", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_3.getValue(),totalPrice.doubleValue(),user.getBalanceSum().doubleValue(), "复购支付金额",orderid);
            yxUserService.incBalancePrice(totalPrice.multiply(new BigDecimal(-1)),Long.parseLong(mainUserId));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《复购支付金额》" + totalPrice.multiply(new BigDecimal(-1)) + "元");
        }
        //String main_whether_slim = mainUser.get("whether_slim").toString();
        if (main_member_level.equals("0")) {
            System.out.println("普通用户：" + mainUserId + "无分润权限");
            return;
        }
        if (!"Y".equals(user.getWhetherVipSlim())) {
           System.out.println("用户：" + mainUserId + "未购买vip礼包产品,无分润权限");
           return;
        }
							/*if (!main_whether_slim.equals("1")) {
								System.out.println("用户：" + mainUserId + "未购买瘦身活动,无分润权限");
								return;
							}*/
        int commissionSum = 0;
        for(int i = Integer.parseInt(main_member_level);i>0;i--) {
            if(i == 5 && team_com_map.containsKey("5") && team_com_map.get("5").equals("Y")) {
                commissionSum = 5 * amount;
                team_com_map.put("5", "N");
                break;
            }
            if(!team_com_map.containsKey(String.valueOf(i))) {
                commissionSum += (commissionSetting.getInteger(String.valueOf(i))*amount);
                team_com_map.put(String.valueOf(i), "Y");
            }
        }


        if(commissionSum>0) {
            BigDecimal commissionTotalSum =new BigDecimal(commissionSum);
            System.out.println("commissionTotalSum=================================="+commissionTotalSum);
           /* BigDecimal balance_sum =(commissionTotalSum.multiply(new BigDecimal("0.1"))).setScale(2, BigDecimal.ROUND_UP);//付存余额
            BigDecimal totalSum =(commissionTotalSum.multiply(new BigDecimal("0.9"))).setScale(2, BigDecimal.ROUND_UP);//利润余额*/
            /*Commission c1= new Commission();
            c1.setCommission_sum(totalSum);
            c1.setCommission_type("7");
            c1.setOrder_id(Long.parseLong(orderid));
            c1.setUser_id(Long.parseLong(mainUserId));
            c1.setRemark("订单分润");
            commissionMgr.addNew(c1);*/
            yxUserBillService.income(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),commissionTotalSum.doubleValue(),user.getNowMoney().doubleValue(), "订单分润",orderid);
            yxUserService.incMoney(Long.parseLong(mainUserId),commissionTotalSum);
            //yxUserService.incBrokeragePrice(totalSum,Long.parseLong(mainUserId));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《提成》" + commissionTotalSum + "元");

            /*Commission c2= new Commission();
            c2.setCommission_sum(balance_sum);
            c2.setCommission_type("11");
            c2.setOrder_id(Long.parseLong(orderid));
            c2.setUser_id(Long.parseLong(mainUserId));
            c2.setRemark("订单分润");
            commissionMgr.addNewBalance(c2);*/
            /*yxUserBillService.income(Long.parseLong(mainUserId),"11", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),balance_sum.doubleValue(),user.getBalanceSum().doubleValue(), "订单分润",orderid);
            yxUserService.incBalancePrice(balance_sum,Long.parseLong(mainUserId));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《复购提成》" + balance_sum + "元");*/
        }
    }

    // 299面膜产品用户分润
    private  void yePayuserSlimmingSale4mmCommissionUpdate(JSONObject mainUser, int index,
                                                                 JSONObject commissionSetting, Map<String, String> team_com_map,
                                                           String orderid, int amount,BigDecimal totalPrice,String payment_id,Map<String, String> team_com_commissionmap,Map<String, String> team_com_pjmap,int pjSum)
            {
        String mainUserId = mainUser.get("id").toString();
        String main_member_level = mainUser.get("member_level").toString();
        int mm_amount =amount;
        totalPrice =totalPrice.setScale(2, BigDecimal.ROUND_UP);
         YxUser user = yxUserService.getById(Long.valueOf(mainUserId));
            //yxUserService.decPrice(Long.parseLong(mainUserId),totalPrice);
            //user = yxUserService.getById(Long.valueOf(mainUserId));
                //BigDecimal totalUserPrice =user.getNowMoney().add(commissionTempSum).subtract(totalPrice);
            /*yxUserBillService.expend4commission(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_3.getValue(),totalPrice.doubleValue(),totalUserPrice.doubleValue(), "积分抵扣",orderid);
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《积分抵扣》" + totalPrice.multiply(new BigDecimal(-1)) + "元");*/
        //String main_whether_slim = mainUser.get("whether_slim").toString();
                String vipcount = storeOrderCartInfoService.getOrderVIPCountByUserid(Long.valueOf(mainUserId));//检查是否有购买299产品
                System.out.println("vipcount=======" + vipcount );
        if (main_member_level.equals("0")) {
            System.out.println("普通用户：" + mainUserId + "无分润权限");
            return;
        }
							/*if (!main_whether_slim.equals("1")) {
								System.out.println("用户：" + mainUserId + "未购买瘦身活动,无分润权限");
								return;
							}*/
        /*if (isEmpty(vipcount) ||Integer.parseInt(vipcount)<1) {
            System.out.println("用户：" + mainUserId + "未购买299礼包,无分润权限");
            return;
        }*/
        if (!"Y".equals(user.getWhetherVipSlim())) {
            System.out.println("用户：" + mainUserId + "未购买vip礼包产品,无分润权限");
            return;
        }
        int commissionSum = 0;
        int pj_commissionSum = 0;
        int pj_sum =pjSum;
        YxUser parentUser =new YxUser();
        String hasParent ="N";
        //User user =userMgr.findById(mainUserId);
        System.out.println("用户user id+等级：" +user.getUid()+"-----"+ user.getLevel() );
        JSONObject jsonObj = yxUserService.getParentByUserid(Long.valueOf(mainUserId),Integer.valueOf(main_member_level));
        String parent_id = jsonObj.getString("parent_id");
        String member_id = jsonObj.getString("member_id");
        log.info("parent_id============="+parent_id);
        log.info("member_id============="+member_id);
        if(!isEmpty(parent_id)){
            if(user.getSpreadUid().intValue() !=0){
                parentUser =yxUserService.getById(user.getSpreadUid());
                if(parentUser.getLevel() <=Integer.parseInt(member_id)){
                    hasParent ="Y";
                }
            }
            System.out.println( "上级parentUser id+等级"+parent_id+"-----"+Integer.parseInt(member_id));

        }
        for(int i = Integer.parseInt(main_member_level);i>0;i--) {
            if(i == 5 && team_com_map.containsKey("5") && team_com_map.get("5").equals("Y")) {
                System.out.println("只有一次:用户user id+等级：" +user.getUid()+"-----"+ user.getLevel() );
                commissionSum = 5;
                team_com_map.put("5", "N");
                break;
            }
            if(!team_com_map.containsKey(String.valueOf(i))) {
                commissionSum += (commissionSetting.getInteger(String.valueOf(i)));
                team_com_map.put(String.valueOf(i), "Y");
            }
        }
                log.info("commissionSum============="+commissionSum);
        if("Y".equals(hasParent)&&commissionSum>0){
            System.out.println("用户user id+等级：" +user.getUid()+"-----"+ user.getLevel() +"==上级用户parentUser id+等级"+parent_id+"-----"+Integer.parseInt(member_id));
            if(user.getLevel()>=3&&(user.getLevel() ==Integer.parseInt(member_id))){
                commissionSum =commissionSum-pj_sum;
                pj_commissionSum =pj_sum;
                System.out.println("用户user等级>=钻石并且上级是同级：" + user.getLevel() +"===用户user commissionSum="+commissionSum+"===用户parentUser pj_commissionSum="+pj_commissionSum);
            }
        }
        if(commissionSum>0) {
            BigDecimal commissionTotalSum =new BigDecimal(commissionSum);
            System.out.println("commissionTotalSum=================================="+commissionTotalSum);
								/*BigDecimal balance_sum =(commissionTotalSum.multiply(new BigDecimal("0.1"))).setScale(2, BigDecimal.ROUND_UP);//付存余额
								BigDecimal totalSum =(commissionTotalSum.multiply(new BigDecimal("0.9"))).setScale(2, BigDecimal.ROUND_UP);//利润余额*/
            //yxUserService.incMoney(Long.parseLong(mainUserId),commissionTotalSum);
            //yxUserService.incBrokeragePrice(commissionTotalSum,Long.parseLong(mainUserId));
            //user = yxUserService.getById(Long.valueOf(mainUserId));
            if(team_com_commissionmap.containsKey(mainUserId)) {
                String s =team_com_commissionmap.get(mainUserId);
                BigDecimal tempSum =new BigDecimal(s).add(commissionTotalSum);
                team_com_commissionmap.put(mainUserId, tempSum.toString());
            }else{
                team_com_commissionmap.put(mainUserId, commissionTotalSum.toString());
            }
            //totalUserPrice =totalUserPrice.add(commissionTotalSum);
            /*yxUserBillService.income(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),commissionTotalSum.doubleValue(),totalUserPrice.doubleValue(), "订单分润",orderid);
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《提成》" + commissionSum + "元");*/

            if(pj_commissionSum>0) {
                BigDecimal pj_commissionTotalSum =new BigDecimal(pj_commissionSum);
                System.out.println("pj_commissionTotalSum=================================="+pj_commissionTotalSum);
                //yxUserService.incMoney(Long.parseLong(parent_id),pj_commissionTotalSum);
                //yxUserService.incBrokeragePrice(pj_commissionTotalSum,Long.parseLong(parent_id));
                if(team_com_pjmap.containsKey(parent_id)) {
                    String s =team_com_pjmap.get(parent_id);
                    BigDecimal tempSum =new BigDecimal(s).add(pj_commissionTotalSum);
                    team_com_pjmap.put(parent_id, tempSum.toString());
                }else{
                    team_com_pjmap.put(parent_id, pj_commissionTotalSum.toString());
                }
                /*YxUser parentuser = yxUserService.getById(Long.valueOf(parent_id));
                BigDecimal parentuserTotalSum = parentuser.getNowMoney().add(pj_commissionTotalSum);
                yxUserBillService.income(Long.parseLong(parent_id),"7", BillDetailEnum.CATEGORY_1.getValue(),
                        BillDetailEnum.TYPE_2.getValue(),pj_commissionTotalSum.doubleValue(),parentuserTotalSum.doubleValue(), "订单分润",orderid);
                System.out.println(main_member_level + "级用户" + parent_id
                        + "：《提成》" + pj_commissionTotalSum + "元");*/

            }
        }


    }

    // 2990面膜产品用户分润
    private  void yePayuserSlimmingSale4NewLiBaoCommissionUpdate(JSONObject mainUser, int index,
                                                           JSONObject commissionSetting, Map<String,
            String> team_com_map,String orderid, int amount,BigDecimal totalPrice,String payment_id,Map<String, String> team_com_commissionmap,Map<String, String> team_com_pjmap)
    {
        String mainUserId = mainUser.get("id").toString();
        String main_member_level = mainUser.get("member_level").toString();
        int mm_amount =amount;
        totalPrice =totalPrice.setScale(2, BigDecimal.ROUND_UP);
        YxUser user = yxUserService.getById(Long.valueOf(mainUserId));
            /*yxUserService.decPrice(Long.parseLong(mainUserId),totalPrice);
            user = yxUserService.getById(Long.valueOf(mainUserId));
            yxUserBillService.expend4commission(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_3.getValue(),totalPrice.doubleValue(),user.getNowMoney().doubleValue(), "积分抵扣",orderid);
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《积分抵扣》" + totalPrice.multiply(new BigDecimal(-1)) + "元");*/
        //String main_whether_slim = mainUser.get("whether_slim").toString();
        String vipcount = storeOrderCartInfoService.getOrderVIPCountByUserid(Long.valueOf(mainUserId));//检查是否有购买299产品
        System.out.println("vipcount=======" + vipcount );
        if (main_member_level.equals("0")) {
            System.out.println("普通用户：" + mainUserId + "无分润权限");
            return;
        }
							/*if (!main_whether_slim.equals("1")) {
								System.out.println("用户：" + mainUserId + "未购买瘦身活动,无分润权限");
								return;
							}*/
        /*if (isEmpty(vipcount) ||Integer.parseInt(vipcount)<1) {
            System.out.println("用户：" + mainUserId + "未购买299礼包,无分润权限");
            return;
        }*/
        if (!"Y".equals(user.getWhetherVipSlim())) {
            System.out.println("用户：" + mainUserId + "未购买vip礼包产品,无分润权限");
            return;
        }
        int commissionSum = 0;
        int pj_commissionSum = 0;
        int pj_sum =50;
        YxUser parentUser =new YxUser();
        String hasParent ="N";
        //User user =userMgr.findById(mainUserId);
        System.out.println("用户user id+等级：" +user.getUid()+"-----"+ user.getLevel() );
        JSONObject jsonObj = yxUserService.getParentByUserid(Long.valueOf(mainUserId),Integer.valueOf(main_member_level));
        String parent_id = jsonObj.getString("parent_id");
        String member_id = jsonObj.getString("member_id");
        if(!isEmpty(parent_id)){
            //parentUser = userMgr.findById(user.getKf_code());
            if(user.getSpreadUid().intValue() !=0){
                parentUser =yxUserService.getById(user.getSpreadUid());
                if(parentUser.getLevel() <=Integer.parseInt(member_id)){
                    hasParent ="Y";
                }
            }
        }
        for(int i = Integer.parseInt(main_member_level);i>0;i--) {
            if(i == 5 && team_com_map.containsKey("5") && team_com_map.get("5").equals("Y")) {
                System.out.println("只有一次:用户user id+等级：" +user.getUid()+"-----"+ user.getLevel() );
                commissionSum = 50 ;
                team_com_map.put("5", "N");
                break;
            }
            if(!team_com_map.containsKey(String.valueOf(i))) {
                commissionSum += (commissionSetting.getInteger(String.valueOf(i)));
                team_com_map.put(String.valueOf(i), "Y");
            }
        }

        if("Y".equals(hasParent)&&commissionSum>0){
            System.out.println("用户user id+等级：" +user.getUid()+"-----"+ user.getLevel() +"==上级用户parentUser id+等级"+parent_id+"-----"+Integer.parseInt(member_id));
            if(user.getLevel()>=3&&(user.getLevel() ==Integer.parseInt(member_id))){
                commissionSum =commissionSum-pj_sum;
                pj_commissionSum =pj_sum;
                System.out.println("用户user等级>=钻石并且上级是同级：" + user.getLevel() +"===用户user commissionSum="+commissionSum+"===用户parentUser pj_commissionSum="+pj_commissionSum);
            }
        }
        if(commissionSum>0) {
            BigDecimal commissionTotalSum =new BigDecimal(commissionSum);
            System.out.println("commissionTotalSum=================================="+commissionTotalSum);
            if(team_com_commissionmap.containsKey(mainUserId)) {
                BigDecimal tempSum =new BigDecimal(team_com_commissionmap.get(mainUserId)).add(commissionTotalSum);
                team_com_commissionmap.put(mainUserId, tempSum.toString());
            }else{
                team_com_commissionmap.put(mainUserId, commissionTotalSum.toString());
            }
            /*yxUserService.incMoney(Long.parseLong(mainUserId),commissionTotalSum);
            //yxUserService.incBrokeragePrice(commissionTotalSum,Long.parseLong(mainUserId));
            user = yxUserService.getById(Long.valueOf(mainUserId));
            yxUserBillService.income(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),commissionTotalSum.doubleValue(),user.getNowMoney().doubleValue(), "订单分润",orderid);
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《提成》" + commissionSum + "元");*/

            if(pj_commissionSum>0) {
                BigDecimal pj_commissionTotalSum =new BigDecimal(pj_commissionSum);
                System.out.println("commissionTotalSum=================================="+commissionTotalSum);
                if(team_com_pjmap.containsKey(parent_id)) {
                    String s =team_com_pjmap.get(parent_id);
                    BigDecimal tempSum =new BigDecimal(s).add(pj_commissionTotalSum);
                    team_com_pjmap.put(parent_id, tempSum.toString());
                }else{
                    team_com_pjmap.put(parent_id, pj_commissionTotalSum.toString());
                }
               /* yxUserService.incMoney(Long.parseLong(parent_id),pj_commissionTotalSum);
                //yxUserService.incBrokeragePrice(pj_commissionTotalSum,Long.parseLong(parent_id));
                YxUser parentuser = yxUserService.getById(Long.valueOf(parent_id));
                yxUserBillService.income(Long.parseLong(parent_id),"7", BillDetailEnum.CATEGORY_1.getValue(),
                        BillDetailEnum.TYPE_2.getValue(),pj_commissionTotalSum.doubleValue(),parentuser.getNowMoney().doubleValue(), "订单分润",orderid);
                System.out.println(main_member_level + "级用户" + parent_id
                        + "：《提成》" + pj_commissionTotalSum + "元");*/

									/*Commission c2= new Commission();
									c2.setCommission_sum(balance_sum);
									c2.setCommission_type("11");
									c2.setOrder_id(Long.parseLong(orderid));
									c2.setUser_id(parentUser.getId());
									c2.setRemark("订单分润");
									commissionMgr.addNewBalance(c2);
									System.out.println(main_member_level + "级用户" + parentUser.getId()
											+ "：《复购提成》" + balance_sum + "元");*/
            }
        }

    }

    // 用户余额支付1390分润
    private  void yePayuserCommissionUpdate4Package(JSONObject mainUser, int index,
                                                          JSONObject commissionSetting, Map<String, String> team_com_map,String orderid, int amount,BigDecimal totalPrice,String payment_id)
    {
        String mainUserId = mainUser.get("id").toString();
        String main_member_level = mainUser.get("member_level").toString();
        int mm_amount =amount/40;
        totalPrice =totalPrice.multiply(new BigDecimal(mm_amount)).setScale(2, BigDecimal.ROUND_UP);
        YxUser user = yxUserService.getById(Long.valueOf(mainUserId));
        if("yue".equals(payment_id)){
            /*Commission c1= new Commission();
            c1.setCommission_sum(totalPrice.multiply(new BigDecimal(-1)));
            c1.setCommission_type("7");
            c1.setOrder_id(Long.parseLong(orderid));
            c1.setUser_id(Long.parseLong(mainUserId));
            c1.setRemark("积分抵扣");
            commissionMgr.addNew(c1);*/
            yxUserService.decPrice(Long.parseLong(mainUserId),totalPrice);
            user = yxUserService.getById(Long.valueOf(mainUserId));
            yxUserBillService.expend4commission(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_3.getValue(),totalPrice.doubleValue(),user.getNowMoney().doubleValue(), "积分抵扣",orderid);
            //yxUserService.incMoney(Long.parseLong(mainUserId),totalPrice.multiply(new BigDecimal(-1)));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《积分抵扣》" + totalPrice + "元");
        }else{
            /*Commission c1= new Commission();
            c1.setCommission_sum(totalPrice.multiply(new BigDecimal(-1)));
            c1.setCommission_type("11");
            c1.setOrder_id(Long.parseLong(orderid));
            c1.setUser_id(Long.parseLong(mainUserId));
            c1.setRemark("复购支付金额");
            commissionMgr.addNewBalance(c1);*/
            yxUserService.decBalancePrice(totalPrice,Long.parseLong(mainUserId));
            user = yxUserService.getById(Long.valueOf(mainUserId));
            yxUserBillService.expend4commission(Long.parseLong(mainUserId),"11", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_3.getValue(),totalPrice.doubleValue(),user.getBalanceSum().doubleValue(), "复购支付金额",orderid);
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《复购支付金额》" + totalPrice + "元");
        }
        if (main_member_level.equals("0")) {
            System.out.println("普通用户：" + mainUserId + "无分润权限");
            return;
        }
        if (!"Y".equals(user.getWhetherVipSlim())) {
            System.out.println("用户：" + mainUserId + "未购买vip礼包产品,无分润权限");
            return;
        }
        int commissionSum = 0;
        for(int i = Integer.parseInt(main_member_level);i>0;i--) {
            if(i == 5 && team_com_map.containsKey("5") && team_com_map.get("5").equals("Y")) {
                commissionSum = 20 * 1;
                team_com_map.put("5", "N");
                break;
            }
            if(!team_com_map.containsKey(String.valueOf(i))) {
                commissionSum += (commissionSetting.getInteger(String.valueOf(i))*1);
                team_com_map.put(String.valueOf(i), "Y");
            }
        }


        if(commissionSum>0) {
            BigDecimal commissionTotalSum =new BigDecimal(commissionSum).setScale(2, BigDecimal.ROUND_UP);
            System.out.println("commissionTotalSum=================================="+commissionTotalSum);
            BigDecimal balance_sum =(commissionTotalSum.multiply(new BigDecimal("0.1"))).setScale(2, BigDecimal.ROUND_UP);//付存余额
            BigDecimal totalSum =(commissionTotalSum.multiply(new BigDecimal("0.9"))).setScale(2, BigDecimal.ROUND_UP);//利润余额
            //YxUser user = yxUserService.getById(Long.valueOf(mainUserId));
            user = yxUserService.getById(Long.valueOf(mainUserId));
            BigDecimal usertotalSum =user.getNowMoney().add(totalSum);
            yxUserBillService.income(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),totalSum.doubleValue(),usertotalSum.doubleValue(), "订单分润",orderid);
            yxUserService.incMoney(Long.parseLong(mainUserId),totalSum);
            //yxUserService.incBrokeragePrice(totalSum,Long.parseLong(mainUserId));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《提成》" + totalSum + "元");
            BigDecimal userBalanceSum =user.getBalanceSum().add(balance_sum);
            yxUserBillService.income(Long.parseLong(mainUserId),"11", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),balance_sum.doubleValue(),userBalanceSum.doubleValue(), "订单分润",orderid);
            yxUserService.incBalancePrice(balance_sum,Long.parseLong(mainUserId));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《复购提成》" + balance_sum + "元");
        }

    }

    // 1390套餐用户分润
    private  void userCommissionUpdate4Package(JSONObject mainUser, int index,
                                                     JSONObject commissionSetting, Map<String, String> team_com_map,String orderid, int amount)
    {
        String mainUserId = mainUser.get("id").toString();
        String main_member_level = mainUser.get("member_level").toString();
        YxUser user = yxUserService.getById(Long.valueOf(mainUserId));
        if (main_member_level.equals("0")) {
            System.out.println("普通用户：" + mainUserId + "无分润权限");
            return;
        }
        if (!"Y".equals(user.getWhetherVipSlim())) {
            System.out.println("用户：" + mainUserId + "未购买vip礼包产品,无分润权限");
            return;
        }
        int commissionSum = 0;
        for(int i = Integer.parseInt(main_member_level);i>0;i--) {
            if(i == 5 && team_com_map.containsKey("5") && team_com_map.get("5").equals("Y")) {
                commissionSum = 20 * 1;
                team_com_map.put("5", "N");
                break;
            }
            if(!team_com_map.containsKey(String.valueOf(i))) {
                commissionSum += (commissionSetting.getInteger(String.valueOf(i))*1);
                team_com_map.put(String.valueOf(i), "Y");
            }
        }


        if(commissionSum>0) {
            BigDecimal commissionTotalSum =new BigDecimal(commissionSum).setScale(2, BigDecimal.ROUND_UP);
            System.out.println("commissionTotalSum=================================="+commissionTotalSum);
            BigDecimal balance_sum =(commissionTotalSum.multiply(new BigDecimal("0.1"))).setScale(2, BigDecimal.ROUND_UP);//付存余额
            BigDecimal totalSum =(commissionTotalSum.multiply(new BigDecimal("0.9"))).setScale(2, BigDecimal.ROUND_UP);//利润余额
            BigDecimal usertotalSum =user.getNowMoney().add(totalSum);
            yxUserBillService.income(Long.parseLong(mainUserId),"7", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),totalSum.doubleValue(),usertotalSum.doubleValue(), "订单分润",orderid);
            yxUserService.incMoney(Long.parseLong(mainUserId),totalSum);
            //yxUserService.incBrokeragePrice(totalSum,Long.parseLong(mainUserId));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《提成》" + totalSum + "元");
            BigDecimal userBalanceSum =user.getBalanceSum().add(balance_sum);
            yxUserBillService.income(Long.parseLong(mainUserId),"11", BillDetailEnum.CATEGORY_1.getValue(),
                    BillDetailEnum.TYPE_2.getValue(),balance_sum.doubleValue(),userBalanceSum.doubleValue(), "订单分润",orderid);
            yxUserService.incBalancePrice(balance_sum,Long.parseLong(mainUserId));
            System.out.println(main_member_level + "级用户" + mainUserId
                    + "：《复购提成》" + balance_sum + "元");
								/*Commission c1= new Commission();
								c1.setCommission_sum(new BigDecimal(commissionSum));
								c1.setCommission_type("7");
								c1.setOrder_id(Long.parseLong(orderid));
								c1.setUser_id(Long.parseLong(mainUserId));
								commissionMgr.addNew(c1);
								System.out.println(main_member_level + "级用户" + mainUserId
										+ "：《提成》" + commissionSum + "元");*/
        }
    }

    // 用户级别调整
    private  void userMemberLevelUpdate(JSONObject mainUser,String orderid,int orderCount)
    {
        Map<String, Integer> firstChildStatistics = new HashMap();
        Map<String, Integer> allChildStatistics = new HashMap();
        String mainUserId = mainUser.get("id").toString();
        log.info("orderCount====="+orderCount);
        String countSum = storeOrderCartInfoService.getOrderCountByUserid(Long.valueOf(mainUserId),Long.valueOf(orderid));
        log.info("countSum====="+countSum);
        int count =orderCount +Integer.valueOf(countSum);
        log.info("count====="+count);
        String vipcount = storeOrderCartInfoService.getOrderVIPCountByUserid(Long.valueOf(mainUserId));//检查是否有购买299产品
        int main_member_level = Integer.parseInt(mainUser.get("member_level")
                .toString());
        String member_id =mainUser.get("member_level")
                .toString();
        String childCount = yxUserService.getChildrens4Main(Long.valueOf(mainUserId),Integer.valueOf(member_id));//获取当前用户的同级直属人数
        System.out.println("获取当前用户的同级直属人数"+childCount +"等级"+member_id+"====单数:"+count);
		/*JSONObject childrens = userMgr.getChildrens(mainUserId);
		int under_count =0;
		int normal_count =0;
		int vip_count =0;
		for (Iterator it = childrens.keys(); it.hasNext();) {
			String key = it.next().toString();
			JSONObject item = childrens.getJSONObject(key);
			String member_level = item.get("member_level").toString();
			if(member_level.equals("1")) {
				normal_count++;
			}else {
				vip_count++;
			}
			if (mainUserId.equals(item.get("kf_code").toString())) {
				under_count++;
				if (firstChildStatistics.containsKey(member_level)) {
					int val = firstChildStatistics.get(member_level);
					firstChildStatistics.put(member_level, ++val);
				} else {
					firstChildStatistics.put(member_level, 1);
				}
			}
			if (allChildStatistics.containsKey(member_level)) {
				int val = allChildStatistics.get(member_level);
				allChildStatistics.put(member_level, ++val);
			} else {
				allChildStatistics.put(member_level, 1);
			}
		}
		userMgr.updateCount(mainUser.get("id").toString(),under_count,normal_count,Integer.parseInt(count));*/
        //userMgr.updateCount4vip(mainUser.get("id").toString(),Integer.parseInt(count));
        YxUser user = yxUserService.getById(Long.valueOf(mainUserId));
        log.info("WhetherVipSlim====="+user.getWhetherVipSlim());
        Integer baseCount =0;
        if(user.getBaseCount() !=null){
            baseCount =user.getBaseCount();
        }
        log.info("baseCount====="+baseCount);
        Integer totalCount =baseCount+count;
        log.info("totalCount====="+totalCount);
        user.setVipCount(totalCount);
        yxUserService.saveOrUpdate(user);
        int updatelevel = 0;
        //if(!Validate.isEmpty(childCount)&&Integer.parseInt(childCount)>=3){
        if(totalCount >= 1 && totalCount <4 &&("Y".equals(user.getWhetherVipSlim()))) {
            updatelevel = 1;
        }else if(totalCount >=4 && totalCount < 40 &&("Y".equals(user.getWhetherVipSlim()))) {
            updatelevel = 2;
        }else if(totalCount >=40 && totalCount < 400 &&(!isEmpty(childCount)&&Integer.parseInt(childCount)>=3) &&("Y".equals(user.getWhetherVipSlim()))) {
            updatelevel = 3;
        }else if(totalCount >=400 && totalCount < 2000 &&(!isEmpty(childCount)&&Integer.parseInt(childCount)>=3) &&("Y".equals(user.getWhetherVipSlim()))&&("Y".equals(user.getIsOpenCrown()))) {
            updatelevel = 4;
        }else if(totalCount >=2000 &&(!isEmpty(childCount)&&Integer.parseInt(childCount)>=3) &&("Y".equals(user.getWhetherVipSlim()))&&("Y".equals(user.getIsOpenLian()))) {
            updatelevel = 5;
        }
        //}

        if(updatelevel > main_member_level) {
            System.out.println("用户"+mainUserId +"升级到"+updatelevel);
            yxUserLevelService.changeUserLevel(Long.valueOf(mainUserId),updatelevel);
            //userMgr.changeMember(mainUserId, String.valueOf(updatelevel));
        }

    }

    // 1390大礼包用户级别调整
    private  void userMemberLevelUpdate4Package(JSONObject mainUser,String orderid,int orderCount)
    {
        Map<String, Integer> firstChildStatistics = new HashMap();
        Map<String, Integer> allChildStatistics = new HashMap();
        String mainUserId = mainUser.get("id").toString();
        String countSum = storeOrderCartInfoService.getOrderCountByUserid(Long.valueOf(mainUserId),Long.valueOf(orderid));
        int count =orderCount +Integer.valueOf(countSum);
        int main_member_level = Integer.parseInt(mainUser.get("member_level")
                .toString());
        String member_id =mainUser.get("member_level")
                .toString();
        String childCount = yxUserService.getChildrens4Main(Long.valueOf(mainUserId),Integer.valueOf(member_id));//获取当前用户的同级直属人数
			/*JSONObject childrens = userMgr.getChildrens(mainUserId);
			int under_count =0;
			int normal_count =0;
			int vip_count =0;
			for (Iterator it = childrens.keys(); it.hasNext();) {
				String key = it.next().toString();
				JSONObject item = childrens.getJSONObject(key);
				String member_level = item.get("member_level").toString();
				if(member_level.equals("1")) {
					normal_count++;
				}else {
					vip_count++;
				}
				if (mainUserId.equals(item.get("kf_code").toString())) {
					under_count++;
					if (firstChildStatistics.containsKey(member_level)) {
						int val = firstChildStatistics.get(member_level);
						firstChildStatistics.put(member_level, ++val);
					} else {
						firstChildStatistics.put(member_level, 1);
					}
				}
				if (allChildStatistics.containsKey(member_level)) {
					int val = allChildStatistics.get(member_level);
					allChildStatistics.put(member_level, ++val);
				} else {
					allChildStatistics.put(member_level, 1);
				}
			}*/
        //userMgr.updateCount(mainUser.get("id").toString(),under_count,normal_count,Integer.parseInt(count));
        //userMgr.updateCount4vip(mainUser.get("id").toString(),Integer.parseInt(count));
        YxUser user = yxUserService.getById(Long.valueOf(mainUserId));
        Integer baseCount =0;
        if(user.getBaseCount() !=null){
            baseCount =user.getBaseCount();
        }
        Integer totalCount =baseCount+count;
        user.setVipCount(totalCount);
        yxUserService.saveOrUpdate(user);

        int updatelevel = 0;
        //if(!Validate.isEmpty(childCount)&&Integer.parseInt(childCount)>=3){
        if(totalCount >= 1 && totalCount <4 &&"Y".equals(user.getWhetherVipSlim())) {
            updatelevel = 1;
        }else if(totalCount >=4 && totalCount < 40 &&"Y".equals(user.getWhetherVipSlim())) {
            updatelevel = 2;
        }else if(totalCount >=40 && totalCount < 400 &&(!isEmpty(childCount)&&Integer.parseInt(childCount)>=3)&&"Y".equals(user.getWhetherVipSlim())) {
            updatelevel = 3;
        }else if(totalCount >=400 && totalCount < 2000 &&(!isEmpty(childCount)&&Integer.parseInt(childCount)>=3) &&"Y".equals(user.getWhetherVipSlim())&&("Y".equals(user.getIsOpenCrown()))) {
            updatelevel = 4;
        }else if(totalCount >=2000 &&(!isEmpty(childCount)&&Integer.parseInt(childCount)>=3) &&"Y".equals(user.getWhetherVipSlim())&&("Y".equals(user.getIsOpenLian()))) {
            updatelevel = 5;
        }
        //}

        if(updatelevel > main_member_level) {
            System.out.println("用户"+mainUserId +"升级到"+updatelevel);
            //userMgr.changeMember(mainUserId, String.valueOf(updatelevel));
            yxUserLevelService.changeUserLevel(Long.valueOf(mainUserId),updatelevel);
        }

    }

    private  void operateCommissionUpdate(String orderid, BigDecimal operateBigDecimal)
    {
        YxStoreOrder order =storeOrderService.getById(orderid);
        Integer provinceId =order.getProvinceId();
        Integer cityId =order.getCityId();
        Integer districtId =order.getDistrictId();
        YxSystemCity district =systemCityService.getOne(Wrappers.<YxSystemCity>lambdaQuery()
                .eq(YxSystemCity::getCityId, districtId));
        if(district != null){
            YxUser user = yxUserService.getOne(Wrappers.<YxUser>lambdaQuery()
                    .eq(YxUser::getAreaId, Long.valueOf(districtId)));
            if(user !=null){
                BigDecimal usertotalSum =user.getNowMoney().add(operateBigDecimal);
                yxUserService.incMoney(user.getUid(),operateBigDecimal);
                //yxUserService.incBrokeragePrice(operateBigDecimal,user.getUid());
                yxUserBillService.income(user.getUid(),"12", BillDetailEnum.CATEGORY_1.getValue(),
                        BillDetailEnum.TYPE_2.getValue(),operateBigDecimal.doubleValue(),usertotalSum.doubleValue(), "区级分润",orderid);
                System.out.println(user.getLevel() + "级用户" + user.getUid()
                        + "：《区级分润》" + operateBigDecimal + "元");
            }
        }
        YxSystemCity city =systemCityService.getOne(Wrappers.<YxSystemCity>lambdaQuery()
                .eq(YxSystemCity::getCityId, cityId));
        if(city != null){
            YxUser user = yxUserService.getOne(Wrappers.<YxUser>lambdaQuery()
                    .eq(YxUser::getAreaId, Long.valueOf(cityId)));
            if(user !=null){
                BigDecimal usertotalSum =user.getNowMoney().add(operateBigDecimal);
                yxUserService.incMoney(user.getUid(),operateBigDecimal);
                //yxUserService.incBrokeragePrice(operateBigDecimal,user.getUid());
                yxUserBillService.income(user.getUid(),"12", BillDetailEnum.CATEGORY_1.getValue(),
                        BillDetailEnum.TYPE_2.getValue(),operateBigDecimal.doubleValue(),usertotalSum.doubleValue(), "市级分润",orderid);
                System.out.println(user.getLevel() + "级用户" + user.getUid()
                        + "：《市级分润》" + operateBigDecimal + "元");
            }
        }
        YxSystemCity province =systemCityService.getOne(Wrappers.<YxSystemCity>lambdaQuery()
                .eq(YxSystemCity::getCityId, provinceId));
        if(province != null){
            YxUser user = yxUserService.getOne(Wrappers.<YxUser>lambdaQuery()
                    .eq(YxUser::getAreaId, Long.valueOf(provinceId)));
            if(user !=null){
                BigDecimal usertotalSum =user.getNowMoney().add(operateBigDecimal);
                yxUserService.incMoney(user.getUid(),operateBigDecimal);
                //yxUserService.incBrokeragePrice(operateBigDecimal,user.getUid());
                yxUserBillService.income(user.getUid(),"12", BillDetailEnum.CATEGORY_1.getValue(),
                        BillDetailEnum.TYPE_2.getValue(),operateBigDecimal.doubleValue(),usertotalSum.doubleValue(), "省级分润",orderid);
                System.out.println(user.getLevel() + "级用户" + user.getUid()
                        + "：《省级分润》" + operateBigDecimal + "元");
            }
        }
        //市级代理
       /* String city =tempAddress[1];
        Area area =new Area();
        List<Area> areaList = systemCityService.list(Wrappers.<Area>lambdaQuery()
                .like(Area::getName, city));
        if(areaList.size()>0){
            area =areaList.get(0);
            List<YxUser> userList = yxUserService.list(Wrappers.<YxUser>lambdaQuery()
                    .like(YxUser::getAreaId, area.getId()));
            if(userList.size()>0){
                YxUser user =userList.get(0);
                //BigDecimal operateBigDecimal =new BigDecimal("2");
                BigDecimal usertotalSum =user.getNowMoney().add(operateBigDecimal);
                yxUserService.incMoney(user.getUid(),operateBigDecimal);
                yxUserService.incBrokeragePrice(operateBigDecimal,user.getUid());
                yxUserBillService.income(user.getUid(),"12", BillDetailEnum.CATEGORY_1.getValue(),
                        BillDetailEnum.TYPE_2.getValue(),operateBigDecimal.doubleValue(),usertotalSum.doubleValue(), "市级分润",orderid);
                System.out.println(user.getLevel() + "级用户" + user.getUid()
                        + "：《市级分润》" + operateBigDecimal + "元");
            }
        }
        //省级代理
        String province =tempAddress[0];
        area =new Area();
        List<Area> areaProvinceList = areaService.list(Wrappers.<Area>lambdaQuery()
                .like(Area::getName, province));
        if(areaProvinceList.size()>0){
            area =areaProvinceList.get(0);
            List<YxUser> userList = yxUserService.list(Wrappers.<YxUser>lambdaQuery()
                    .like(YxUser::getAreaId, area.getId()));
            if(userList.size()>0){
                YxUser user =userList.get(0);
                //BigDecimal operateBigDecimal =new BigDecimal("2");
                BigDecimal usertotalSum =user.getNowMoney().add(operateBigDecimal);
                yxUserService.incMoney(user.getUid(),operateBigDecimal);
                yxUserService.incBrokeragePrice(operateBigDecimal,user.getUid());
                yxUserBillService.income(user.getUid(),"12", BillDetailEnum.CATEGORY_1.getValue(),
                        BillDetailEnum.TYPE_2.getValue(),operateBigDecimal.doubleValue(),usertotalSum.doubleValue(), "省级分润",orderid);
                System.out.println(user.getLevel() + "级用户" + user.getUid()
                        + "：《省级分润》" + operateBigDecimal + "元");
            }
        }*/
    }

    public void traderMoney(YxUser fromUser,YxUser toUser, BigDecimal traderSum)
    {
        //扣减当前用户余额
        yxUserService.decPrice(fromUser.getUid(),traderSum);
        BigDecimal fromUsertotalSum =fromUser.getNowMoney().subtract(traderSum);
        BigDecimal toUsertotalSum =toUser.getNowMoney().add(traderSum);
        yxUserBillService.expend4traderCommission(fromUser.getUid(),toUser.getUid(),"15", BillDetailEnum.CATEGORY_1.getValue(),
                BillDetailEnum.TYPE_3.getValue(),traderSum.doubleValue(),fromUsertotalSum.doubleValue(), "积分转账",toUser.getPhone(), BillEnum.PM_0.getValue());
//增加目标用户余额
        yxUserBillService.expend4traderCommission(toUser.getUid(),fromUser.getUid(),"15", BillDetailEnum.CATEGORY_1.getValue(),
                BillDetailEnum.TYPE_2.getValue(),traderSum.doubleValue(),toUsertotalSum.doubleValue(), "转账获取积分",fromUser.getPhone(), BillEnum.PM_1.getValue());
        yxUserService.incMoney(toUser.getUid(),traderSum);
        //yxUserService.incBrokeragePrice(traderSum,toUser.getUid());
    }

    // 推三返一产品分润
    private  void rebateOrderCommission(String user_id, String goods_id,
                                          String combinationId,String orderid) {
        YxUser user = yxUserService.getById(Long.valueOf(user_id));
        YxStoreCombination storeCombination = storeCombinationService.getById(Long.valueOf(combinationId));
        YxUser parentUser = new YxUser();
        BigDecimal rebateBigDecimal =new BigDecimal("0");
        if(user.getSpreadUid() != null && user.getSpreadUid() > 0){
            parentUser =yxUserService.getById(user.getSpreadUid());
            int count =storePinkService.getPinkOk4selfRebateSumTotalNum(user.getSpreadUid(),Long.valueOf(combinationId));
            if(count>0){
                int remainder =count%storeCombination.getPeople();//余数
                if(remainder ==0){
                    rebateBigDecimal =storeCombination.getPrice();
                }else{
                    rebateBigDecimal =storeCombination.getCommissionSum();
                }
            }
            if(rebateBigDecimal.compareTo(new BigDecimal("0")) ==1){
                BigDecimal usertotalSum =parentUser.getNowMoney().add(rebateBigDecimal);
                yxUserService.incMoney(parentUser.getUid(),rebateBigDecimal);
                //yxUserService.incBrokeragePrice(rebateBigDecimal,parentUser.getUid());
                yxUserBillService.income(parentUser.getUid(),"13", BillDetailEnum.CATEGORY_1.getValue(),
                        BillDetailEnum.TYPE_2.getValue(),rebateBigDecimal.doubleValue(),usertotalSum.doubleValue(), "推三返一分润",orderid);
                log.info(parentUser.getLevel() + "级用户" + parentUser.getUid()
                        + "：《推三返一分润》" + rebateBigDecimal + "元");
            }
        }
    }

    // 余额支付推三返一产品分润
    private  void yueRebateOrderCommission(String user_id, String goods_id,
                                        String combinationId,String orderid) {
        YxUser user = yxUserService.getById(Long.valueOf(user_id));
        YxStoreCombination storeCombination = storeCombinationService.getById(Long.valueOf(combinationId));
        yxUserBillService.expend4commission(Long.parseLong(user_id),"7", BillDetailEnum.CATEGORY_1.getValue(),
                BillDetailEnum.TYPE_3.getValue(),storeCombination.getPrice().doubleValue(),user.getNowMoney().doubleValue(), "积分抵扣",orderid);
        yxUserService.decPrice(Long.parseLong(user_id),storeCombination.getPrice());
        log.info(user.getLevel() + "级用户" + user_id
                + "：《积分抵扣》" + storeCombination.getPrice().multiply(new BigDecimal(-1)) + "元");
        YxUser parentUser = new YxUser();
        BigDecimal rebateBigDecimal =new BigDecimal("0");
        if(user.getSpreadUid() != null && user.getSpreadUid() > 0){
            parentUser =yxUserService.getById(user.getSpreadUid());
            int count =storePinkService.getPinkOk4selfRebateSumTotalNum(user.getSpreadUid(),Long.valueOf(combinationId));
            if(count>0){
                int remainder =count%storeCombination.getPeople();//余数
                if(remainder ==0){
                    rebateBigDecimal =storeCombination.getPrice();
                }else{
                    rebateBigDecimal =storeCombination.getCommissionSum();
                }
            }
            if(rebateBigDecimal.compareTo(new BigDecimal("0")) ==1){
                BigDecimal usertotalSum =parentUser.getNowMoney().add(rebateBigDecimal);
                yxUserService.incMoney(parentUser.getUid(),rebateBigDecimal);
                //yxUserService.incBrokeragePrice(rebateBigDecimal,parentUser.getUid());
                yxUserBillService.income(parentUser.getUid(),"13", BillDetailEnum.CATEGORY_1.getValue(),
                        BillDetailEnum.TYPE_2.getValue(),rebateBigDecimal.doubleValue(),usertotalSum.doubleValue(), "推三返一分润",orderid);
                log.info(parentUser.getLevel() + "级用户" + parentUser.getUid()
                        + "：《推三返一分润》" + rebateBigDecimal + "元");
            }
        }
    }

    // 秒杀产品分润
    private  void seckillOrderCommission(String user_id, String goods_id,
                                        String seckillId,String orderid,int amount) {
        YxUser user = yxUserService.getById(Long.valueOf(user_id));
        YxStoreSeckill storeSeckill = yxStoreSeckillService.getById(Long.valueOf(seckillId));
        YxUser parentUser = new YxUser();
        BigDecimal seckillBigDecimal =new BigDecimal("0");
        if(user.getSpreadUid() != null && user.getSpreadUid() > 0){
            parentUser =yxUserService.getById(user.getSpreadUid());
            seckillBigDecimal =storeSeckill.getCommissionSum().multiply(new BigDecimal(amount));
            if(seckillBigDecimal.compareTo(new BigDecimal("0")) ==1){
                BigDecimal usertotalSum =parentUser.getNowMoney().add(seckillBigDecimal);
                yxUserService.incMoney(parentUser.getUid(),seckillBigDecimal);
                //yxUserService.incBrokeragePrice(seckillBigDecimal,parentUser.getUid());
                yxUserBillService.income(parentUser.getUid(),"16", BillDetailEnum.CATEGORY_1.getValue(),
                        BillDetailEnum.TYPE_2.getValue(),seckillBigDecimal.doubleValue(),usertotalSum.doubleValue(), "秒杀分润",orderid);
                System.out.println(parentUser.getLevel() + "级用户" + parentUser.getUid()
                        + "：《秒杀分润》" + seckillBigDecimal + "元");
            }
        }
    }

    // 余额支付秒杀产品分润
    private  void yueSeckillOrderCommission(String user_id, String goods_id,
                                           String seckillId,String orderid,int amount) {
        YxUser user = yxUserService.getById(Long.valueOf(user_id));
        YxStoreSeckill storeSeckill = yxStoreSeckillService.getById(Long.valueOf(seckillId));
        yxUserBillService.expend4commission(Long.parseLong(user_id),"7", BillDetailEnum.CATEGORY_1.getValue(),
                BillDetailEnum.TYPE_3.getValue(),storeSeckill.getPrice().doubleValue(),user.getNowMoney().doubleValue(), "积分抵扣",orderid);
        yxUserService.incMoney(Long.parseLong(user_id),storeSeckill.getPrice().multiply(new BigDecimal(-1)));
        System.out.println(user.getLevel() + "级用户" + user_id
                + "：《积分抵扣》" + storeSeckill.getPrice().multiply(new BigDecimal(-1)) + "元");
        YxUser parentUser = new YxUser();
        BigDecimal seckillBigDecimal =new BigDecimal("0");
        if(user.getSpreadUid() != null && user.getSpreadUid() > 0){
            parentUser =yxUserService.getById(user.getSpreadUid());
            seckillBigDecimal =storeSeckill.getCommissionSum().multiply(new BigDecimal(amount));
            if(seckillBigDecimal.compareTo(new BigDecimal("0")) ==1){
                BigDecimal usertotalSum =parentUser.getNowMoney().add(seckillBigDecimal);
                yxUserService.incMoney(parentUser.getUid(),seckillBigDecimal);
                //yxUserService.incBrokeragePrice(seckillBigDecimal,parentUser.getUid());
                yxUserBillService.income(parentUser.getUid(),"16", BillDetailEnum.CATEGORY_1.getValue(),
                        BillDetailEnum.TYPE_2.getValue(),seckillBigDecimal.doubleValue(),usertotalSum.doubleValue(), "秒杀分润",orderid);
                System.out.println(parentUser.getLevel() + "级用户" + parentUser.getUid()
                        + "：《秒杀分润》" + seckillBigDecimal + "元");
            }
        }
    }

    /**
     * 判断对象是否为空（包括空指针、空字符串、空集合）
     *
     * @param obj
     *          需要判断的对象
     * @return true：对象为空；false：对象不为空。
     */
    public static boolean isEmpty(Object obj) {
        if (obj instanceof String) {
            String s = (String) obj;
            if ((s == null) || s.trim().length() == 0) {
                return true;
            }
        } else if (obj instanceof Collection) {
            if (obj == null || ((Collection) obj).size() == 0)
                return true;
        } else if (obj instanceof Map) {
            if (obj == null || ((Map) obj).size() == 0)
                return true;
        } else if (obj == null) {
            return true;
        }
        return false;
    }
}
